110,534
社区成员
发帖
与我相关
我的任务
分享
public partial class Component1 : Control
{
TextBox box = new TextBox();
public Component1()
{
InitializeComponent();
box.BorderStyle = BorderStyle.None;
//这儿需要的事件自己加
this.Controls.Add(box);
}
[DefaultValue("")]
public new string Text
{
get { return box.Text ; }
set
{
box.Text = value;
}
}
int r = 7;
[ Category("布局"), Description("倒角半径。")]
public int R
{
get { return r; }
set
{
r= value;
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
int w = R * 2;
base.OnPaintBackground(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(0, 0, w , w, 180, 90);
path.AddArc(this.Width - w -1, 0, w, w, -90, 90);
path.AddArc(this.Width - w -1, this.Height - w-1, w, w, 0, 90);
path.AddArc(0, this.Height - w -1, w, w, 90, 90);
path.CloseFigure();
e.Graphics.FillPath(Brushes.White, path);
using (Pen pen = new Pen(Color.Green ))
{
e.Graphics.DrawPath(pen, path);
}
}
}
private void Component1_Resize(object sender, EventArgs e)
{
box.Left = Height/2;
box.Top = Height/2 - box.Height /2;
box.Width = this.Width - Height ;
}
}
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport("gdi32.dll")]
static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
private void Form1_Load(object sender, System.EventArgs e)
{
Int32 width = textBox1.Width;
Int32 height = textBox1.Height;
SetWindowRgn(this.textBox1.Handle, CreateRoundRectRgn(2, 2, width, height, width, height), true);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(0, 0, Height - 1, Height - 1, 90, 180);
path.AddArc(Width - Height, 0, Height - 1, Height - 1, 270, 180);
path.CloseFigure();
e.Graphics.FillPath(Brushes.White, path);
using (Pen pen = new Pen(Color.Green ))
{
e.Graphics.DrawPath(pen, path);
}
}
}