日期:2014-05-18 浏览次数:22107 次
[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); } } }