I have a 2 form application - the first form opens the second form, which
allows a user to create a file. The first form then needs to do something
based on how the form was closed.

how the code looks
Dim tf As New frmNewLeague
tf.ShowDialog()

If < tf closed using save button > Then
do stuff
else
do other stuff
End If

Is using a global variable the best way, or can you cature how a form is
closed?

Derruck

Re: capturing how a form was closed by Javier

Javier
Thu Feb 26 17:45:07 CST 2004


"Derrick" <Derrick_no_spam@geostrategies.ca> escribió en el mensaje
news:9pu%b.625437$ts4.598934@pd7tw3no...
> I have a 2 form application - the first form opens the second form, which
> allows a user to create a file. The first form then needs to do something
> based on how the form was closed.
>
> how the code looks
> Dim tf As New frmNewLeague
> tf.ShowDialog()
>
> If < tf closed using save button > Then
> do stuff
> else
> do other stuff
> End If
>
> Is using a global variable the best way, or can you cature how a form is
> closed?
>

You use DialogResult for that, buttons have a DialogResult property which
you can set to make them close and send a result to ShowDialog();

For example, if you set a button with an "OK" dialog result, and another one
with a "Cancel" one, you would:

(i'm a C# writer, i'll try my best at writing VB.Net code, but I've never
done this before)

Dim tf As New frmNewLeague
Dim mr As DialogResult

mr = tf.ShowDialog()
if mr = DialogResult.OK then
' do whatever for ok
elseif mr = DialogResult.Cancel then
' do whatever for cancel
else ' the form was closed with the 'x' button
' do whatever
end if

There are other dialog results, like "Yes", "No", "Abort", etc.

Take into account, that if the button has a DialogResult property associated
(not 'none'), it'll automatically close the form (or, technically called
'end the dialog'), and you don't have to manually call 'Close()' on the
form.

Hope this helps, and hope the above code is right (lemme repeat: i've never
coded any vb.net, nor any vb since version 2 for the matter ;D)

Javier Campos



Re: capturing how a form was closed by hirf-spam-me-here

hirf-spam-me-here
Thu Feb 26 17:50:13 CST 2004

* "Derrick" <Derrick_no_spam@geostrategies.ca> scripsit:
> I have a 2 form application - the first form opens the second form, which
> allows a user to create a file. The first form then needs to do something
> based on how the form was closed.
>
> how the code looks
> Dim tf As New frmNewLeague
> tf.ShowDialog()
>
> If < tf closed using save button > Then
> do stuff
> else
> do other stuff
> End If
>
> Is using a global variable the best way, or can you cature how a form is
> closed?

Set the form's 'DialogResult' property and use something like this:

\\\
Select Case tf.DhowDialog()
Case DialogResult.OK
...
Case DialogResult.Cancel
...
...
End Select
///

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!

RE: capturing how a form was closed by v-yiy

v-yiy
Thu Feb 26 21:41:43 CST 2004

Hi Derrick,

You may set the DialogResult property of the Button in the PropertyGrid in
the designer view and then use the suggestions from our community members.

If you still have problem on this issue, please feel free to reply in this
thread.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.


Re: capturing how a form was closed by Derrick

Derrick
Thu Feb 26 22:49:49 CST 2004

Thanks so much for all (Javier Campos, Herfried K. Wagner and Ying-Shen)
your help again - that worked perfectly.

Derrick


""Ying-Shen Yu[MSFT]"" <v-yiy@online.microsoft.com> wrote in message
news:C$ASeOO$DHA.612@cpmsftngxa06.phx.gbl...
> Hi Derrick,
>
> You may set the DialogResult property of the Button in the PropertyGrid in
> the designer view and then use the suggestions from our community members.
>
> If you still have problem on this issue, please feel free to reply in this
> thread.
>
>
> Best regards,
>
> Ying-Shen Yu [MSFT]
> Microsoft community Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
> This mail should not be replied directly, please remove the word "online"
> before sending mail.
>