Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I need to build custom button and make button shape like "L"
latter

public class mybutton : Button
    {  
         protected override void  OnPaint(PaintEventArgs pevent)
         {
          How do this ????????????????????????
         }
    }
Posted
Updated 25-Aug-11 5:07am
v2

This is actually quite simple.
You must set the Region property of your button.

Something like this in the constructor...
using(var path = new GraphicsPath())
{
    path.AddEllipse(Bounds);
    Region = new Region(path);
}

...will make your button an ellipse as wide & tall as the original size.

In order to make an 'L' shape, you will need to add rectangles to the path instead.

Note: You will still want to override the OnPaint method to draw it yourself.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 25-Aug-11 19:52pm    
Finally a correct answer! There are "real" non-rectangular buttons, but many make lousy buttons which only seem to be non-rectangular because they do not modify Region, only paint something; the cheating can be easily detected with a mouse. IGood, I voted I5 :-)
--SA
Ian Good 25-Aug-11 20:05pm    
hey thanks for the 5

Regions are pretty wacky; You can change a Form's Region any way you see fit as well, so you can come up with a very unique user interface for your application, which could be a quirky fun feature for clients, or simply annoying :P
Sergey Alexandrovich Kryukov 25-Aug-11 23:14pm    
This is true of course.
--SA
There's a ton of articles on the web about making custom button controls.

For example, try this one[^].
 
Share this answer
 
This isn't as easy as it sounds. What you want to do is extract the Graphics object from the PaintEventArgs and use drawing primitives on that to draw your button. You need to consider though that buttons change their look when focused, pressed down etc.
 
Share this answer
 
Easy if you are using Expression blend and WPF. Just drag a picutre on to the Design layout and turn the picture into a button.

You are using WinForms though (OnPaint), so my recomendation is to use WPF :D
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900