Windows Develop Bookmark and Share   
 index > Windows Forms Designer > IS it possible to make a triangle shaped button?
 

IS it possible to make a triangle shaped button?

I’m not even sure if this is possible. I’m writing a game that is based on triangles

And I want to make an array of tri-angle shaped buttons. I don’t even know where to look

to work out if this can or can not be done ?

Frank Paul  Friday, March 10, 2006 5:22 AM
There are many possible ways to create a non-rectangular button, either draw it yourself, modify the Control's region or use a Bitmap Region. Here's an example from codeproject that uses Bitmap Region technique:
http://www.codeproject.com/csharp/bmprgnform.asp

For other approach, you can seach codeproject, there are tons of articles in there that describes in detail on how to create non-rectangular controls, though they may not be exactly Triangular controls, you can easily convert them.

Regards,

-chris
Chris Vega  Friday, March 10, 2006 5:53 AM
There are many possible ways to create a non-rectangular button, either draw it yourself, modify the Control's region or use a Bitmap Region. Here's an example from codeproject that uses Bitmap Region technique:
http://www.codeproject.com/csharp/bmprgnform.asp

For other approach, you can seach codeproject, there are tons of articles in there that describes in detail on how to create non-rectangular controls, though they may not be exactly Triangular controls, you can easily convert them.

Regards,

-chris
Chris Vega  Friday, March 10, 2006 5:53 AM
Hi,
Just override the OnPaint event of the inherited Button from Sytem.Windows.Forms.Button and draw the triangle. Also set the region of the control to the region of the triangle so thatc button area is defined.

protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.HighQuality;
float h = this.Height;
float w = this.Width;
PointF[] pts = new PointF[] { new PointF(w / 2, 0), new PointF(0, w), new PointF(w, h) };
g.FillPolygon(Brushes.Gray, pts);
GraphicsPath gp=new GraphicsPath();
gp.AddPolygon(pts);
this.Region = new Region(gp);
}
  • Proposed As Answer bynitroxn Friday, July 03, 2009 9:59 PM
  •  
nitroxn  Friday, July 03, 2009 9:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Feature rich .NET ComboBox control released!
• How to modify RichTextBox bullet
• scroll bar is hidden in my user control
• User Control + URI formats are not supported
• Code Definition Window
• [C++] how can i save graphic to an image file ?
• How to customize the selection border of selected control in VS2005 (WinForm)
• Method 'System.Windows.Forms.Form.setOutputFile' not found.
• Global Right Mouse Click at Design Time
• Forms Design View