Question : how do you close x2 winforms programmically

how do you close x2 winforms programmically ?

basically, have WinForm1 which has a menubar strip -- select login option (for example).

a login window appears (WinForm2) -- press the enter button -- if user is successfully authenticated then close the currently opened Login winform2 and then also the previously opened Winform1.

have programmed everything upto the point of being able to close the original WinForm1 ... WinForm2 closes ok, but cannot seem to see where the processing flow re-entered WinForm1 in order to catch this and automate that WinForm1 to close also.

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
:: use the following to close WinForms
 
private void closeAgentLoginWindow()
        {
            try
            {
                this.Dispose();
            }
            catch (COMException ex)
            {
                showError(ex);
            }
        }
 
 
:: use the following to open WinForms
 
private void openAgentLoginWindow()
        {
            try
            {
                AgentLogin formAgentLogin = new AgentLogin();
                formAgentLogin.ShowDialog();
            }
            catch (COMException ex)
            {
                showError(ex);
            }
        }

Answer : how do you close x2 winforms programmically

"...but cannot seem to see where the processing flow re-entered WinForm1..."

Your code in the first form STOPS at the ShowDialog() call until the secondary form is closed:

    AgentLogin formAgentLogin = new AgentLogin();
    formAgentLogin.ShowDialog(); // code STOPS here until "formAgentLogin" is finished
    // continue with code here making a decision based on the results!...
Random Solutions  
 
programming4us programming4us