Public partial class Form3:form {const int wm_nchittest = 0x0084; const int ht_left = 10; const int ht_right = 11; const int ht_top = 12; const int ht_topleft = 13; const int ht_topright = 14; const int ht_bottom = 15; const int ht_bottomleft = 16; const int ht_bottomright = 17; const int ht_caption = 2; Public Form3 () {InitializeComponent (); Rectregion = new System.Drawing.Rectangle (0, 0, this. Width, this. Height); Setwindowregion (); } private System.Drawing.Rectangle rectregion; private static int x, y = 0; public void Setwindowregion () {System.Drawing.Drawing2D.GraphicsPath formpath; Formpath = new System.Drawing.Drawing2D.GraphicsPath (); System.Drawing.Rectangle rect = new System.Drawing.Rectangle (0, 0, this. Width, this. Height); Formpath = Getroundedrectpath (rect,10); This. Region = new Region (Formpath); } protected override void OnPaint (PaintEventArgs e) {Graphics g = e.graphics; System.Drawing.Drawing2D.GraphicsPath Formpath; System.Drawing.Rectangle rect = new System.Drawing.Rectangle (0, 0, this. Width, this. Height); Formpath = Getroundedrectpath (rect, 10); Pen mypen = new Pen (Color.gray, 2); G.drawpath (Mypen, Formpath); Base. OnPaint (e); } private GraphicsPath Getroundedrectpath (System.Drawing.Rectangle rect, int radius) {int Diamet er = radius; System.Drawing.Rectangle arcrect = new System.Drawing.Rectangle (rect. Location, new Size (diameter, diameter)); GraphicsPath path = new GraphicsPath (); The upper-left corner of path. AddArc (Arcrect, 180, 90); upper right corner arcrect.x = rect. Right-diameter; Path. AddArc (Arcrect, 270, 90); lower right corner Arcrect.y = rEct. Bottom-diameter; Path. AddArc (arcrect, 0, 90); lower left corner arcrect.x = rect. Left; Path. AddArc (Arcrect, 90, 90); Path. Closefigure ();//closed curve return path; } protected override void WndProc (ref Message MSG) {if (msg.msg = = wm_nchittest) { Get mouse position int nposx = (Msg.LParam.ToInt32 () & 65535); int nposy = (Msg.LParam.ToInt32 () >> 16); Lower right corner if (nposx >= this. Right-6 && Nposy >= this. Bottom-6) {Msg.result = new IntPtr (ht_bottomright); Return }//upper left corner else if (nposx <= this. Left + 6 && nposy <= this. Top + 6) {Msg.result = new IntPtr (ht_topleft); Return }//lower left corner else if (nposx <= this. Left + 6 && nposy >= this. Bottom-6) {Msg.result = new IntPtr (ht_bottomleft); Return }//upper right corner else if (nposx >= this. Right-6 && Nposy <= this. Top + 6) {Msg.result = new IntPtr (ht_topright); Return } else if (Nposx >= this. Right-2) {Msg.result = new IntPtr (ht_right); Return } else if (Nposy >= this. Bottom-2) {Msg.result = new IntPtr (ht_bottom); Return } else if (Nposx <= this. Left + 2) {Msg.result = new IntPtr (ht_left); Return } else if (Nposy <= this. Top + 2) {Msg.result = new IntPtr (ht_top); Return } else {msg.result = new IntPtr (ht_caption); Return }} base. WndProc (ref MSG); } private void Form3_resize (object sender, EventArgs e) {SetStyle (controlstyles.supportstranspar Entbackcolor, True); SetStyle (Controlstyles.allpaintinginwmpaint, true); SetStyle (Controlstyles.userpaint, true); SetStyle (Controlstyles.doublebuffer, true); This. Refresh (); Setwindowregion (); private void btnClose_Click (object sender, EventArgs e) {this. Close (); private void Btnmax_click (object sender, EventArgs e) {this. MaximumSize = new Size (Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); This. WindowState = formwindowstate.maximized; private void Btnmin_click (object sender, EventArgs e) {this. MinimumSize = new Size (rectregion.width, rectregion.height); This. WindowState = Formwindowstate.normal; private void Panel1_mousedown (object sender, MouseEventArgs e) {x = e.x-1; y = e.y-1; private void Panel1_mousemove (object sender, MouseEventArgs e) {if (E.button = = MOUSEBUTTONS.L EFT) {this. left = Cursor.position.x-x; This. Top = cursor.position.y-y; } } }
Demo <a target=_blank href= "http://download.csdn.net/detail/u011470119/7589233" >http://download.csdn.net/ Detail/u011470119/7589233</a>