首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

winform如何把textbox变成圆角

2012-09-01 
winform怎么把textbox变成圆角picturebox + textbox + 圆角图片。。这种效果不是很好。。能不能到达这种效果。。

winform怎么把textbox变成圆角
picturebox + textbox + 圆角图片。。这种效果不是很好。。
能不能到达这种效果。。
http://my.csdn.net/my/album/detail/1239337

[解决办法]
用图片效果还不好啊。

网页上也是用图片和CSS实现的
[解决办法]
找几个设置窗体的API,把窗体的句柄换成TextBox的
TextBox也是窗体嘛

比如:

C# code
        [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);        }
[解决办法]
探讨

引用:

找几个设置窗体的API,把窗体的句柄换成TextBox的
TextBox也是窗体嘛

比如:
C# code
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);

[DllImport("gdi3……

……

[解决办法]
重写OnPaintBackground 事件
C# code
  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);                }            }        } 

热点排行