1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.Linq;7 usingSystem.Text;8 usingSystem.Windows.Forms;9 Ten namespaceNoboarder One { A Public Partial classFormparent:form - { - Publicformparent () the { - InitializeComponent (); - } - + protected BOOLIsmousedown =false; - protectedPoint formlocation; + protectedPoint mouseoffset; A at Private voidFormparent_mousedown (Objectsender, MouseEventArgs e) - { - if(E.button = =mousebuttons.left) - { -Ismousedown =true; -Formlocation = This. Location; inMouseoffset =control.mouseposition; - to } + } - the Private voidFormparent_mousemove (Objectsender, MouseEventArgs e) * { $ intx =0;Panax Notoginseng inty =0; - if(Ismousedown) the { +Point pt =control.mouseposition; Ax = Mouseoffset.x-Pt. X; they = mouseoffset.y-Pt. Y; + This. Location =NewPoint (Formlocation.x-x, FORMLOCATION.Y-y); - } $ } $ - Private voidFormparent_mouseup (Objectsender, MouseEventArgs e) - { theIsmousedown =false; - }Wuyi } the}
Set the FormBorderStyle of the form to none, running the window with no boundaries to move.
In the program, a number of non-border windows can directly inherit this class, in order to facilitate understanding, this inherits from the form of the class called Formparent, and Add a button above, Text = "ParentForm"
Add code to its Click event
1 Private void button1_click (object sender, EventArgs e)2 {3 New Formson (); 4 f.show (); 5 This . Hide (); 6 }
Create a new Windows Form, named Formson, to inherit from Formparent
1 Public Partial class // !!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 3 Public Formson () 4 {5 InitializeComponent (); 6 }7 }
Run the program click Formparent will pop up exactly the same formson out, it is really biological
But people always have personality, we modify Formson button control, found that can not be modified, in fact, this is not a family genetic disease, is because the Formparent Modifires property settings for private, change to public on it!