Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounded Corners in C# windows forms [duplicate]

I have a window without borders. I searched net for rounded corners but all with borders. How can i make rounded corners of the form(not with borders) ? Is there a way to do that?

I am a newbie to c#, so please explain...

Thanks

like image 823
Hari krishnan Avatar asked Sep 16 '13 06:09

Hari krishnan


People also ask

What is CSS rounded corners?

CSS3 Rounded corners are used to add special colored corner to body or text by using the border-radius property.A simple syntax of rounded corners is as follows − #rcorners7 { border-radius: 60px/15px; background: #FF0000; padding: 20px; width: 200px; height: 150px; }

How do I round the corners of an image in CSS?

The border-radius CSS property is what adds the rounded corners. You can experiment with different values to get it the way you like. border-radius: 75px; If you want it to be a circle, add border-radius: 50%; .


3 Answers

try this:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        [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, // width of ellipse
            int nHeightEllipse // height of ellipse
        );

        public Form1()
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.None;
            Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
        }
    }
}

from here: Form with Rounded Borders in C#?

like image 179
AsfK Avatar answered Oct 12 '22 00:10

AsfK


The Region propery simply cuts off the corners. To have a true rounded corner you will have to draw the rounded rectangles.

Drawing rounded rectangles

It might be easier to draw an image of the shape you want and put that on the transparent form. Easier to draw but cannot be resized.

Also check this Another One

like image 26
Vinay Pratap Singh Bhadauria Avatar answered Oct 12 '22 00:10

Vinay Pratap Singh Bhadauria


I found this code

To come up with the rounded corners textbox, I started trying to work with the paint override event, but unfortunately without any result, which is due to the fact (I assume) that the textbox is derived from Windows. Therefore, I tried overriding the WM_PAINT API instead, which had the desired results

http://www.codeproject.com/Articles/17453/Textbox-with-rounded-corners

Thanks

like image 34
Moayad Myro Avatar answered Oct 11 '22 23:10

Moayad Myro