0

I have created a Windows Forms Custom Control inheriting from class Button in order to get a round button:

public partial class RoundButton : Button
{
    public RoundButton()
    {
        InitializeComponent();

        Width = 16;
        Height = 16;
        FlatStyle = FlatStyle.Flat;
        FlatAppearance.BorderSize = 0;
        BackColor = SystemColors.ControlDark;
    }

    public sealed override Color BackColor
    {
        get => base.BackColor; 
        set => base.BackColor = value;
    }

    protected override void OnPaint(PaintEventArgs pe)
    {
        GraphicsPath grPath = new GraphicsPath();
        grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
        Region = new Region(grPath);

        base.OnPaint(pe);
    }
}

When I add the RoundButton control to a form in the designer its property Text is automatically assigned a value (roundButton1). I have tried to "clear" the property in the constructor, but that doesn't work:

Text = string.Empty;

How do I make sure that the property Text has no value when adding the control in the designer? I don't want to "clear" the property in the Properties window in the designer. The property should be "cleared" by default when added in the designer.

Andy Rehn
  • 131
  • 6
  • 2
    That text is set by the Control's Designer. You have to replace it with a custom one (derived from [ControlDesigner](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.design.controldesigner)). Not clear if you actually want to allow to set the Text after, or the Control should not have text at all -- The Region of a Control is not set in `OnPaint()`, but in `OnResize()` / `OnLayout()` -- If you create a round Region that way, the Control is going to look terrible + no anti-alias at all – Jimi Oct 20 '22 at 08:43
  • See, for example: [How to draw a shape using GraphicsPath to create the Region of a Custom Control?](https://stackoverflow.com/a/69075782/7444103) and [How to avoid visual artifacts of colored border of zoomable UserControl with rounded corners?](https://stackoverflow.com/a/54794097/7444103) – Jimi Oct 20 '22 at 08:54

0 Answers0