SIMPLE C#/기초
[SIMPLE C#] 둥근버튼(Round Button) 만들기
작마
2023. 5. 20. 00:39
나만의 컨트롤 만들기 1탄! Round Button
※ 모서리를 지정 값 만큼 둥글게 만들어서 path 를 반환 하는 함수
private GraphicsPath CreateRoundRectPath(int x, int y, int width, int height, int cornerRadius)
{
GraphicsPath path = new GraphicsPath();
if (cornerRadius == 0)
{
path.AddRectangle(new Rectangle(x, y, width, height));
}
else
{
path.AddArc(x, y, cornerRadius, cornerRadius, 180, 90); // 왼쪽 상단 모서리
path.AddArc(x + width - cornerRadius, y, cornerRadius, cornerRadius, 270, 90);// 오른쪽 상단 모서리
path.AddArc(x + width - cornerRadius, y + height - cornerRadius, cornerRadius, cornerRadius, 0, 90);// 오른쪽 하단 모서리
path.AddArc(x, y + height - cornerRadius, cornerRadius, cornerRadius, 90, 90);// 왼쪽 하단 모서리
}
path.CloseFigure();
return path;
}
※ 컨트롤 제작시 기본 파라미터
public UserControl1()
{
InitializeComponent();
// Set Optimized Double Buffer to reduce flickering
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
// Redraw when resized
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.Resize += (s1, e1) => { this.Invalidate(); };
}
영상의 내용을 외울 필요는 없습니다. 어떤 경우에 사용을 했구나 하는 점만 기억하면 좋겠습니다
이 글은 최초 : http://tindevil.com/?p=638 에서 배포 되었습니다
반응형