Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

In reading some of the other posts about when the main form closes it terminates the application, I've had to take a different methodology to my login screen.

 

I've modified my frmMain as follows:

 

 

    Public Sub New()
       MyBase.New()

       'Show Login Screen and Validate Credentials
       Dim Login As frmLogin
       Login = New frmLogin()
       Login.ShowDialog(Me)

       'This call is required by the Windows Form Designer.
       InitializeComponent()   
       ...

 

I've also created a public property called "LoggedIn" which contains a boolean value.

 

What I would like to do is after the .ShowDialog returns the control to frmMain, check to see if this value is True, if so continue, if not terminate.

 

I've tried the following code but it generates an exception error:

 

Public Sub New()
       MyBase.New()

       'Show Login Screen and Validate Credentials
       Dim Login As frmLogin
       Login = New frmLogin()
       Login.ShowDialog(Me)

       If Not Global.blnLoggedIn Then
             Me.Close()
       End If

       'This call is required by the Windows Form Designer.
       InitializeComponent()
       ...

 

I know I could call the frmLogin from within the frmMain_Load sub, but I don't want the main form to show before the person enters their credentials. The workflow would have looked something like this:

 

       1: LoginScreen displayed to user
       2: Credentials entered are validated
       3: If credentials are valid, goto frmMain and close LoginScreen
       4: else stay on this screen for three retries, then end

 

Any ideas? TIA!

 

M.

  • *Gurus*
Posted

Public Sub ShowMyDialogBox()
   Dim testDialog As New Form2()
   
   ' Show testDialog as a modal dialog and determine if DialogResult = OK.
   If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
       ' Read the contents of testDialog's TextBox.
       result.Text = testDialog.TextBox1.Text
   Else
       result.Text = "Cancelled"
   End If
   testDialog.Dispose()
End Sub 'ShowMyDialogBox

 

You can set the value of DialogResult in the properties of each of the dialog's buttons.

Posted

Thanks Derek, but where do I place your code? In my frmMain and then call it like this:

 

Public Sub New()
       MyBase.New()

       'Show Login Screen and Validate Credentials
       Call ShowMyDialogBox()

       'This call is required by the Windows Form Designer.
       InitializeComponent()   
       ...

Thanks again!

M.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...