winform设置边框颜色不像webform那么简单,可以通过设置FlatAppearance,也可以通过重绘实现。
一、设置按钮本身属性
| 1 2 3 | buttonBubufx.FlatStyle = FlatStyle.Flat;buttonBubufx.BackColor = Color.SkyBlue;buttonBubufx.FlatAppearance.BorderColor = buttonBubufx.BackColor; | 
二、重绘,设置按钮的Region
| 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 | privatestaticintWM_NCPAINT = 0x0085;       privatestaticintWM_ERASEBKGND = 0x0014;       privatestaticintWM_PAINT = 0x000F;       [DllImport("user32.dll")]       staticexternIntPtr GetDCEx(IntPtr hwnd, IntPtr hrgnclip, uintfdwOptions);       [DllImport("user32.dll")]       staticexternintReleaseDC(IntPtr hwnd, IntPtr hDC);       protectedoverridevoidWndProc(refMessage m)       {           base.WndProc(refm);           if(m.Msg == WM_NCPAINT || m.Msg == WM_ERASEBKGND || m.Msg == WM_PAINT)           {               IntPtr hdc = GetDCEx(m.HWnd, (IntPtr)1, 1 | 0x0020);               if(hdc != IntPtr.Zero)               {                   Graphics graphics = Graphics.FromHdc(hdc);                   Color borderColor = Color.HotPink;                   Rectangle rectangle = newRectangle(textBox1.Location.X, textBox1.Location.Y + (25), textBox1.Width, textBox1.Height);                   ControlPaint.DrawBorder(graphics, rectangle, borderColor, ButtonBorderStyle.Solid);                   m.Result = (IntPtr)1;                   ReleaseDC(m.HWnd, hdc);               }           }       } | 
原帖地址:winform设置button的边框颜色,或取消边框颜色,不显示边框。
bubufx提供,禁止转载。
winform设置button的边框颜色,或取消边框颜色,不显示边框
原文:http://www.cnblogs.com/weekzero/p/3514964.html