Word dialog does not appear on top.

H

hayrob

My CAB WinForm application invokes Word to open a document.
When the document is closed, the app handles the DocumentBeforeClose event
and if the document has not been saved, shows a "Do you want to save the
document?" dialog (using MessageBox.Show).
The dialog is shown in the TaskBar but is ALWAYS hidden. How can I make it
ALWAYS appear on top?
Thanks.
 
H

hayrob

If anyone is interested, this works:
If MsgBox("Do you want to save the Document?",
MsgBoxStyle.YesNo Or MsgBoxStyle.MsgBoxSetForeground, "Confirm close") =
MsgBoxResult.Yes Then
Cancel = True
Exit Sub
Else
Doc.Saved = True
mDocFile = String.Empty
End If

There is no equivalent using MessageBox.Show.
I created a custom form to provide the dialog and used the Windows API -

[DllImport("User32.dll")]
public static extern Int32 SetForegroundWindow(IntPtr hWnd);

and that did the trick!
 

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