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
controls = new List(); - 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
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.

Sachin SinghRank #66 · 26.2K reputationPosted Nov 17, 2020, 11:03 PM EST
Denis Morgan84 reputationPosted Nov 17, 2020, 11:12 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Nov 17, 2020, 11:17 PM EST
Denis Morgan84 reputationPosted Nov 17, 2020, 11:28 PM EST
@Sachin Singh I want to add a badge(Label) not image
Denis Morgan84 reputationPosted Nov 17, 2020, 11:50 PM EST