Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe you would need 3 classes:</p> <ol> <li>a <strong>login</strong> form, where the user will authenticate by inserting the credentials and clicking the <code>loginButton</code></li> <li>a <strong>main</strong> form, to hold the menu strip, where the other forms could be shown by pressing the menu buttons</li> <li>the <strong>child</strong> form, which will have a <code>logoutButton</code> and other custom controls (so basically you can derive other child forms from it)</li> </ol> <p>In the <strong>login</strong> form, handle the login button click like this:</p> <pre><code>private void loginButton_Click(object sender, EventArgs e) { if (Authenticated(username.Text, password.Text)) { var mainForm = new MainForm(); this.Visible = false; mainForm.Show(this); } } </code></pre> <p>The main form, add a handler for the form closing event and some handlers for showing the children:</p> <pre><code>public MainForm() { InitializeComponent(); FormClosing += MainForm_FormClosing; } void MainForm_FormClosing(object sender, FormClosingEventArgs e) { this.Owner.Visible = true; } private void form1ToolStripMenuItem_Click(object sender, EventArgs e) { var childForm = new ChildForm(); childForm.Show(this); } </code></pre> <p>In the child form, when clicking on the <code>logoutButton</code>, get a reference to the owner of the child form (which will be the <strong>main</strong> form), close it's owned forms (all it's children) and close the <strong>main</strong> form itself:</p> <pre><code>private void logoutButton_Click(object sender, EventArgs e) { var owner = ((MainForm)this.Owner); foreach (var childForm in owner.OwnedForms) { childForm.Close(); } owner.Close(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload