blog

I like to blog about current software design and development projects, as well as general everyday news and events. I'm passionate about what I do and you can follow my personal journey through my blog. I'm constantly on the lookout for new development techniques and technologies to keep on top of the changing market, so if I do miss anything feel free to leave me a comment.

Windows Forms with Rounded Corners

Have you ever found yourself developing a custom user interface and needed rounded corners which work on different Windows Operating Systems?

If you are using Windows Vista this is easily achieved by using a rounded PNG image with transparent corners and setting the transparency property. This however does not work on systems such as Windows XP.

The following C# code can be used to ensure you have rounded corners on a number of Windows Operating Systems.

1
2
3
4
5
6
7
8
9
10
11
12
13
[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
);
 
// Set your own values
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(1, 1, 10, 10 16, 16));

Tags: , , ,

2 Responses to “Windows Forms with Rounded Corners”

  1. Sahand // March 12th, 2009 at 1:41 am

    Hi,
    I have problem to create Rounded Forms with special design which is designed in photoshop with files: dxf or jpg/bmp in .NET Compact Visual Studio 2005 C#.
    .NET Comapct is very limited version of .NET platform and there is no Image Property for Forms in .NET Compact version.
    How i can create exactly the Image forms in my development project in Windows CE (Windows Mobile 6).

    Thanks in Advance.
    /Sahand

  2. Beno Gorancic // March 12th, 2009 at 9:17 pm

    Sorry but I haven’t played enough with .Net Compact Framework to be able to help you out.

    I think you need to take a different approach if you want rounded corners but my suggestion is that you don’t do that. I personally would work with the default themes.

    Sorry I couldn’t be of more help.

Leave a Reply