Form Lost Focus

M

Miro

VB 2005 Express.

I have an MDI app, and I have a child form loading in the Parent form.
On the Child form I have a command button "Close". Upon click of that
close,

If MessageBox.Show("Are you sure you want to cancel?", _
"Cancel", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly) = Windows.Forms.DialogResult.Yes Then
Me.Close()
Me.Dispose()
End If

This works proper... however I loose focus to the Entire Application.
Even when I try to put something like this after it: frmMainForm.Focus()
, this does nothing.

Am I missing something in my closing / disposing ?

Thanks

Miro
 
C

Charles May

Not sure what the DefaultDesktopOnly does (didn't read up on it) but if you
take out that option it appears to work.

CM
 
M

Miro

Learn something new every day.

I thought it was more with my disposing and closing or some property I had
set on the form rather than the messagebox itself.
That will teach me to always start at the "very beginning" of the problem.

Thank you CM,

It makes sense once I read up on the DefaultDesktopOnly Parm.
-The program was doing exactly what I told it to do, not what I wanted it to
do. ;)

Miro

---
DefaultDesktopOnly
The message box is displayed on the active desktop.
This constant is the same as ServiceNotification except that the system
displays the message box only on the default desktop of the interactive
window station.
 
C

Charles May

Great, Glad it worked.
Miro said:
Learn something new every day.

I thought it was more with my disposing and closing or some property I had
set on the form rather than the messagebox itself.
That will teach me to always start at the "very beginning" of the problem.

Thank you CM,

It makes sense once I read up on the DefaultDesktopOnly Parm.
-The program was doing exactly what I told it to do, not what I wanted it
to do. ;)

Miro

---
DefaultDesktopOnly
The message box is displayed on the active desktop.
This constant is the same as ServiceNotification except that the system
displays the message box only on the default desktop of the interactive
window station.
 
Joined
Aug 22, 2011
Messages
1
Reaction score
0
If you pass in zero as the MessageBoxOptions parameter value it will be removed from FxCop and won’t cause application focus issues.

MessageBox.Show("Changes Successful", Utilities.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0);

Available options with MessageBoxOptions
MessageBoxOptions.DefaultDesktopOnly Causes application to loose focus

MessageBoxOptions.RightAlign Right aligns text. Multi-line message box looks awkward.

MessageBoxOptions.RtlReading Turns Message Box to right to left reading (weird for English language)

MessageBoxOptions.ServiceNotification Causes application to loose focus
 

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