-
Notifications
You must be signed in to change notification settings - Fork 0
/
EllipseControl.cs
39 lines (36 loc) · 1.21 KB
/
EllipseControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace ClipLab
{
public class EllipseControl : Component
{
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn(int nL, int nT, int nR, int nB, int nWidthEllipse, int nHeightEllipse);
private Control control;
private int cornerRadius = 25;
public Control TargetControl
{
get { return control; }
set
{
control = value;
control.SizeChanged += (sender, eventArgs) => control.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, control.Width, control.Height, cornerRadius, cornerRadius));
}
}
public int CornerRadius
{
get { return cornerRadius; }
set
{
cornerRadius = value;
if (control != null)
control.Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, control.Width, control.Height, cornerRadius, cornerRadius));
}
}
}
}