how to create round corner button in c#.net.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted May 29, 2015, 8:16 AM
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing.Drawing2D;
public class UserControl1
{
//Radius of the Corner Curve
private Int32 _radius = 20;
//Opacity of the Control
private Int32 _opacity = 125;
//Back Color of Control
private System.Drawing.Color _backColor = Color.Black;
private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Rectangle rect = this.ClientRectangle;
//Drawing Rounded Rectangle
rect.X = rect.X + 1;
rect.Y = rect.Y + 1;
rect.Width -= 2;
rect.Height -= 2;
using (GraphicsPath bb = GetPath(rect, _radius)) {
using (Brush br = new SolidBrush(Color.FromArgb(_opacity, _backColor))) {
e.Graphics.FillPath(br, bb);
}
}
}
//Returns the GraphicsPath to Draw a RoundedRectangle
protected GraphicsPath GetPath(Rectangle rc, Int32 r)
{
Int32 x = rc.X;
Int32 y = rc.Y;
Int32 w = rc.Width;
Int32 h = rc.Height;
r = r << 1;
GraphicsPath path = new GraphicsPath();
if (r > 0) {
if ((r > h))
r = h;
if ((r > w))
r = w;
path.AddArc(x, y, r, r, 180, 90);
path.AddArc(x + w - r, y, r, r, 270, 90);
path.AddArc(x + w - r, y + h - r, r, r, 0, 90);
path.AddArc(x, y + h - r, r, r, 90, 90);
path.CloseFigure();
} else {
path.AddRectangle(rc);
}
return path;
}
public UserControl1()
{
Paint += UserControl1_Paint;
}
}
MBGlassButton.dll reference in your project.Nanhe SiddiquePosted May 29, 2015, 7:19 AM
Nilesh JadavPosted May 29, 2015, 6:46 AM
Pankaj Kumar ChoudharyPosted May 29, 2015, 6:46 AM
http://www.codeproject.com/Articles/15730/RoundButton-Windows-Control-Ever-Decreasing-Circle
Dipankar BiswasPosted May 29, 2015, 6:05 AM