newbie with a VisualBasic.NET Winforms problem

B

Bob

I have a function - UserSaysSave() - that asks user if they want to
save using System.Windows.Forms.MessageBox and Returns the Result.

Function UserSaysSave() As Boolean
if MessageBox.Show(strText, strCaption, MessageBoxButtons.YesNo,
MessageBoxIcon.Question, DefaultBtn) = DialogResult.Yes) Then
boolOK = True
End If
Return boolOK
--
In a btn_Click event I call this function and if they say no it should
do nothing and return them to the window/form/screen they were using
before MessageBox.Show() was called.

Sub btn_Click()
If UserSaysSave() Then
' Save code
End If
''' active window here should be the one prior to UserSaysSave(), yes?
End Sub

But it does *not* return them to the correct window/form/screen! It
Activates a different window, that's also open, instead of the one
prior to MessageBox.

No matter what I try, Me.Activate, me.BringToFront. Me.Show, it still
Activates the wrong window/form/screen directly after MessageBox.

I must confess here that the window/form/screen I expect to return to
is a TabPage (of a TabControl).

Any suggestions would be greatly appreciated

Thanks,
Bob
 
C

Cor

Hi Bob,

As far as I can see it,
Then your form on which the button is should stay on screen in its position
with the messagebox upon it.

But maybe you can set in top of your program
option explicit on and also option Strict on

It give messages if you do something wrong.

I hope this helps

Cor
 
B

Bob

Thanks for your response Cor.
I found the answer late last night - I had fiddled with OnLostFocus
weeks ago, also late night, and forgot the experiment.
(Good suggestion on Options Explicit and Strict, I always use them.)
Bob

--------------
 

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