469,330 Members | 1,289 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

How do I create windows forms with rounded corners?

"David" <da*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
so, the questuion,
How can I create windows (forms) with rounded corners?

David.

Nov 16 '05 #1
3 40808
hi David
what you can do is to use the classes of Graphics to override the Onpaint
method of the form ( where the form is printed ) you may need to read about
using GDI classes.
check these articles

http://www.devhood.com/tutorials/tut...tutorial_id=24
http://www.dotnet247.com/247reference/msgs/2/11921.aspx
http://www.c-sharpcorner.com/2/gdi_plus.asp

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2
There's a much easier way to round the edges of a windows control. Use the
Windows API function CreateRoundRectRgn(). The abbreviated example below
shows how to do it to a form.

yourform.cs
....
using System.Runtime.InteropServices;
....
[DllImport("Gdi32.dll", EntryPoint="CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);

public Form1() // Your form's or other control's constructor
{
InitializeComponent();
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn( 0, 0,
Width-10, Height-10, 20, 20)); // adjust these parameters to get the look
you want.
}
....

ShaneB

"Mohamoss" <mo************@egdsc.microsoft.com> wrote in message
news:H%****************@cpmsftngxa10.phx.gbl...
hi David
what you can do is to use the classes of Graphics to override the Onpaint
method of the form ( where the form is printed ) you may need to read
about
using GDI classes.
check these articles

http://www.devhood.com/tutorials/tut...tutorial_id=24
http://www.dotnet247.com/247reference/msgs/2/11921.aspx
http://www.c-sharpcorner.com/2/gdi_plus.asp

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #3
ShaneB,

Thanks for helping David.
I came in between because he wasn't asking his question in a way that would
get him an answer.
He has the answer now. Thanks again.
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Konrad | last post: by
3 posts views Thread by Rod Gill | last post: by
2 posts views Thread by Dino Buljubasic | last post: by
8 posts views Thread by TheCornjerker | last post: by
6 posts views Thread by Schraalhans Keukenmeester | last post: by
4 posts views Thread by PWS | last post: by
2 posts views Thread by Terry | last post: by
6 posts views Thread by moondaddy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.