Form Lost Focus

  • Thread starter Thread starter Miro
  • Start date Start date
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
 
Not sure what the DefaultDesktopOnly does (didn't read up on it) but if you
take out that option it appears to work.

CM
 
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.
 
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.
 
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
 
Back
Top