TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Denis Morgan
NA
72
22.5k
How to add a badge to a tabpage in a tabcontrol
Nov 18 2020 3:34 AM
I need to add a badge to a tab control at the top right corner. I have tried this and came up with this class
public
class
BadgeUtil
{
private
static
List<Control> controls =
new
List<Control>();
static
public
bool
AddBadgeTo(Control ctl,
string
Text,
int
y,
int
x)
{
if
(controls.Contains(ctl))
return
false
;
Badge badge =
new
Badge();
// badge.AutoSize = true;
badge.Size =
new
Size(20, 20);
badge.Text = Text;
badge.BackColor = Color.FromA#ff8040;
controls.Add(ctl);
ctl.Controls.Add(badge);
SetPosition(badge, ctl,x,y);
return
true
;
}
static
private
void
SetPosition(Badge badge, Control ctl,
int
x,
int
y)
{
badge.Location =
new
Point(x,
y);
}
class
Badge : Label
{
Color BackColor = Color.SkyBlue;
Color ForeColor = Color.White;
Font font =
new
Font(
"Sans Serif"
, 9f);
public
Action<Control> ClickEvent;
public
Badge() { }
protected
override
void
OnPaint(PaintEventArgs e)
{
e.Graphics.FillEllipse(
new
SolidBrush(Color.FromA#ff0000),
this
.ClientRectangle);
e.Graphics.DrawString(Text, font,
new
SolidBrush(ForeColor), 3, 1);
}
protected
override
void
OnClick(EventArgs e)
{
ClickEvent(
this
);
}
}
}
and used this way
BadgeUtil.AddBadgeTo(tabPage3,
"3"
,0,120);
which is resulting to this un desired output. I would like my badge to be position on the blue circle of the tab control as shown in this image not where the badge is positioned.
Reply
Answers (
5
)
Rotate and crop and save image in MVC?
How to make a web api.