Form Operations in VB.NET

M

Max

I've done quiet a bit of VB programming using versions 5 and 6. Now I
finally got my hands on .NET and all I can say is "I am soooo lost".
Would appreciate it if you guys could help me out with some basic form
operations. I've already figured out how to load new forms and do all of
that, but now I have this problem...

I have a form that starts the program. From there I have a button which
creates a new form, shows it, and disables the first one. Now when the
second form is closed I need to re-enable the first form. How do I go
about doing that? While I'm at it, what else should I take a look at in
regard to differences in form operations between VB6 and VB.NET? I'll
probably run into some other problems later so it would be nice to know
it ahead of time. Thanks for your help.
 
S

Scott

Instead of trying to disable/enable the main form, why not just use the
ShowDialog method to show the second form as a modal dialog. This
automatically prevents the user from modifying any control on the first form
until the second form is closed or hidden.

In general, use Show() to load a form as a normal window and ShowDialog() to
load the form as a modal form or dialog box. Also, check the return value of
these functions to determine why the second form was dismissed. The return
value can be set using the DialogResult variable of the form.

For instance, if your second form had 2 buttons labeled "OK" and "Cancel"
you could assign them values of DialogResult.OK and DialogResult.Cancel,
respectively. Then you could check the return value of the ShowDialog method
as shown below to determine which button was clicked so that you could
perform any necessary actions.

Dim MyForm2 as New Form2

If MyForm2.ShowDialog(Me) = DialogResult.OK Then
' OK button was clicked
Else
' Cancel button was clicked or form was closed another way
End If

Hope this helps,

Scott
 
M

Max

Scott said:
Instead of trying to disable/enable the main form, why not just use the
ShowDialog method to show the second form as a modal dialog. This
automatically prevents the user from modifying any control on the first form
until the second form is closed or hidden.

In general, use Show() to load a form as a normal window and ShowDialog() to
load the form as a modal form or dialog box. Also, check the return value of
these functions to determine why the second form was dismissed. The return
value can be set using the DialogResult variable of the form.

For instance, if your second form had 2 buttons labeled "OK" and "Cancel"
you could assign them values of DialogResult.OK and DialogResult.Cancel,
respectively. Then you could check the return value of the ShowDialog method
as shown below to determine which button was clicked so that you could
perform any necessary actions.

Dim MyForm2 as New Form2

If MyForm2.ShowDialog(Me) = DialogResult.OK Then
' OK button was clicked
Else
' Cancel button was clicked or form was closed another way
End If

Hope this helps,

Scott

That is perfect, exactly what I needed. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top