A custom tool(circle button) that is created by a class does not appear in toolbox after rebuild (VS 2022)

Joined
Sep 26, 2022
Messages
16
Programming Experience
1-3
I was trying to create a round button. For this, we need to create a class, here is the code:
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace CircularButton
{
    internal class CircularButton :Button
    {
        protected override void OnPaint(PaintEventArgs pevent)
        {
            GraphicsPath g = new GraphicsPath();
            g.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
            this.Region = new System.Drawing.Region(g);
            base.OnPaint(pevent);
        }
    }
}
After creating and coding this class, we need to rebuild the solution, after rebuilding, we must see the new CİRCLE BUTTON tool in the TOOLBOX:

1664195001935.png


However, I do not get neither this circule button option nor the "applicationName Components" tab:

1664195033417.png



I do not have both. How can I solve this problem?


Source of the images I use is this video:
 
Last edited by a moderator:
internal class CircularButton
Change to public class, then rebuild (possibly Clean Solution first, then Rebuild solution) and reopen designer for a form. It should now appear in toolbox.
 
About graphics code:
  • GraphicsPath should be disposed in that code block, after it has been used to the create the new Region object.
  • If Region property is not null it should be disposed before you assign a new Region object.
 
Also... Are you sure that you want to keep or creating a new region every time your button is painted? You should only do that whenever the width and/or height has changed.
 

Latest posts

Back
Top Bottom