Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Return a <code>DialogResult</code> upon closing your Form1. Use that value in <code>Main()</code> to determine if you should open Form2 or not. Something like this.</p> <p>In Form1, perhaps in a button click handler:</p> <pre><code>this.DialogResult = DialogResult.OK; this.Close(); </code></pre> <p>In Program.cs:</p> <pre><code>Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var form1 = new Form1(); Application.Run(form1); if (form1.DialogResult == DialogResult.OK) { Application.Run(new Form2()); } </code></pre> <p>If your Form1 closes without setting its <code>DialogResult</code> to <code>DialogResult.OK</code>, your application will exit. If your Form1 closes and its <code>DialogResult</code> is set to <code>DialogResult.OK</code> then Form2 will open.</p> <hr> <p>Edit: <strong>Using this technique for simple logons</strong></p> <p>Here's one approach.</p> <p>Create an enum which describes the result of your logon screen:</p> <pre><code>public enum LogonStatus { NoLogon, UserA, UserB }; </code></pre> <p>On your logon screen create a property to store the logon result:</p> <pre><code>public LoggedOnUser User { get; private set; } </code></pre> <p>In the logon form assign a value to the logon operation and close the form:</p> <pre><code>LogonResult = LogonStatus.UserA; // UserA logged in, for example. this.Close(); </code></pre> <p>In Main run the Logon form, examine the form's <code>LogonResult</code> proeprty and process the result: </p> <pre><code>static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var loginForm = new Form_Login(); Application.Run(loginForm); if (loginForm.LogonResult == LogonStatus.NoLogon) { // Do something because there was no logon, or do nothing here and let your app exit. } else { // Launch your application form, passing in the logged on user. Application.Run(new AppForm(loginForm.LogonResult)); } } </code></pre> <p>This example shows passing a <code>LogonStatus</code> to your <code>AppForm</code>'s constructor to allow you to tailor it the user logged on.</p> <p><strong>With the above said though, you should know this isn't really the best way to do this. A more flexible and robust solution would involve taking advantage of Windows directory services.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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