日期:2014-05-18  浏览次数:22046 次

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);
                }
            }
        }