Modeless - Show
If the button event handlers call the Me.Dispose before they call Me.Close then the FormClosing event is not called.
The FormClosing event however is always called if you use the corner cross.
Dim dlgDialog As New frmDialog()
Modeless - TopMost within Application
There is a property called TopMost but the problem with this is that it displays the windows form on top of everything (i.e. all application windows).
What you really want is for a windows form to just be the topmost in that particular application.
This is possible by passing in the windows handler for the parent application.
This is only necessary when a form is displayed as modeless but you want the form to remain on top of the active workbook or document.
In Excel the object model can provide you with this handle
In Word the object model cannot so we need to get the handle using windows API.
Dim objDialog As New frmDialog()
Dim objNativeWindow As System.Windows.Forms.NativeWindow
Dim objHandle As System.IntPtr
objNativeWindow = New System.Windows.Forms.NativeWindow
'Excel provides access to the window handle as part of the object model
objHandle = New IntPtr(gExcelApplication.Hwnd)
'Word does not so you need to use the Windows API
objHandle = clsWin32.FindWindow("OpusApp", gWordApplication.ActiveDocument.Name & " - " & gWordApplication.Caption)
'PowerPoint does not so you need to use the Windows API
objHandle = clsWin32.FindWindow("PPFrameClass", gPowerPoint.ActivePresentation & " - " & gPowerPointApplication.Caption)
objHandle = Nothing
You must remember to dispose of the handle when the windows form is closed.
© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext