Use a Windows Form as a Function

I have a login form I will be using a few times in my app.

How do i call this form like a function.  So the form is displayed and allow the use to confirm their login and when the form is closed it returns true or false.
Kevin RobinsonPrivate VB.NET ContractorAsked:
Who is Participating?
ZeonFlashConnect With a Mentor Commented:
You can show the form modally and then receive a DialogResult (which can be specified inside the login form) as a returned result.  Here's an example:

'Create the login form
Dim frmLogin As New LoginForm
Dim dlgResult As DialogResult = frmLogin.ShowDialog()

If dlgResult = DialogResult.Yes Then
      'Login successful
ElseIf dlgResult = DialogResult.No Then
      'Login failed
End If

Inside the login form, you can set the result that will be returned like this:

                  Me.DialogResult = DialogResult.Yes

In your Main form declare a public shared function where you display your form.
In all other forms call your shared function
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.