No border removable form

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.