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.
Denis MorganPosted Nov 18, 2020, 4:50 AM
Denis MorganPosted Nov 18, 2020, 4:28 AM
@Sachin Singh I want to add a badge(Label) not image
Sachin SinghPosted Nov 18, 2020, 4:17 AM
Denis MorganPosted Nov 18, 2020, 4:12 AM
Sachin SinghPosted Nov 18, 2020, 4:03 AM