
Round The Edges Of A Control In C#
The following code snippet will make the edges of windows form round shaped.
The other windows controls including buttons, combo boxes, list boxes, etc. could also be made round shaped. Just replace “this” with the control name when calling the function “GetRoundedRegion”,
[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 ); //function call, it will return the rounded region of the given region public static System.Drawing.Region GetRoundedRegion(int controlWidth, int controlHeight) { return System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, controlWidth– 5, controlHeight– 5, 12, 12)); } //the following Line of Code will round the edges of C# form this.Region = GetRoundedRegion(this.Width, this.Height);
Healthcare software development, HL7 Interface, EMR/EHR integration, mHealth, HIPAA compliant