Windows Form-----Content (8)

Source: Internet
Author: User

form Type:
SDI MDI
Single Document form interface, multi-document form interface

One, single document form interface:
There is one main form, and the other forms are secondary forms and dialog boxes.
Once the main form is turned off, the entire program ends.

Case one: How do I log in?
1. Determine the main form. In the Program.cs file, in the main function, use Application.Run () to start the main form.
Application.Run (New Main ());
2. Make a login form.
When login verification is complete, do not close the form or display the main form. Only need to give this. DialogResult assigns a value.
private void Button1_Click (object sender, EventArgs e)
{
Verify that the user name and password are correct
if (TextBox1.Text = = "AAA" && TextBox2.Text = = "BBB")
{
This. DialogResult = System.Windows.Forms.DialogResult.OK;
}
Else
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
3. In the main function of Program.cs, start the login form (Start with a dialog box) before Application.Run () runs the main form
If the dialog box returns a successful identity, run the following Application.Run ();
Form1 f = new Form1 ();
DialogResult result = F.showdialog ();
if (result = = DialogResult.OK)
{
Application.Run (New Main ());
}

Second, multi-document form interface:
A parent form that contains multiple subforms. The subform cannot be moved outside the form, and the parent form closes the subform off.
1. Determine the parent form. Set the properties of the parent form: Ismdiparent = True
2. Make a subform.
3. In the form's code, instantiate the subform.
4. Set the properties of the subform: MdiParent, set as parent form object
ChildForm f = new ChildForm ();
F.mdiparent = this; Here, this represents the parent form object.
5. Show Subform
F.show ();

Important properties in the parent form:
Ismdiparent-is the parent form bool
Mdichildren-A collection of all the subforms. Form[]
Activemdichild-the child form that is currently on the top level. Form

Case one: Use the menu to add multiple subforms, close all subforms, and close the current subform.

Case two: Only one subform is generated. If you already have a subform, you are no longer adding a new subform.
public partial class Mdiform:form
{
Public MDIForm ()
{
InitializeComponent ();
}

private void Mdiform_load (object sender, EventArgs e)
{
Otherform om = new Otherform ();
Om. MdiParent = this;
Om. Show ();
}

private void New Subform Toolstripmenuitem_click (object sender, EventArgs e)
{
ChildForm child = new ChildForm ();
Child. MdiParent = this;
Child. Show ();
}

private void closes the current subform Toolstripmenuitem_click (object sender, EventArgs e)
{
ChildForm child = this. Activemdichild as ChildForm;
Child. Close ();
}

private void Closes all subforms Toolstripmenuitem_click (object sender, EventArgs e)
{
foreach (ChildForm. Mdichildren)
{
Child. Close ();
}
}

private void Toolstripmenuitem1_click (object sender, EventArgs e)
{
BOOL Isexsite = false;
foreach (Form child in this.) Mdichildren)
{
if (Child is ChildForm)
{
Isexsite = true;
Break
}
}
if (Isexsite = = False)
{
ChildForm child = new ChildForm ();
Child. MdiParent = this;
Child. Show ();
}
}
}

Windows Form-----Content (8)

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.