Show/hide form when application loses focus

Show/hide form when application loses focus

Neil-Star
Participant Participant
309 Views
4 Replies
Message 1 of 5

Show/hide form when application loses focus

Neil-Star
Participant
Participant

I have a user form that sits on specific ribbon and moves along with window and so mimics a bespoke panel in ribbon.

The only thing I've not managed to do is hide it when the main inventor window loses focus, (ie you click on the desktop or another window/program while leaving the inventor one running in background) it stays there top most. 

Is there a method where by when the main inventor window loses focus that the form hides and shows again once the inventor window regains focus?

 

TIA 

0 Likes
Accepted solutions (1)
310 Views
4 Replies
Replies (4)
Message 2 of 5

C_Haines_ENG
Collaborator
Collaborator

I do not think there is a way of doing this, with the main limiter being that there is no Event Trigger for the application being maximized or minimized. 

 

If you had a rule running in the background constantly checking Inventors window state then maybe you could achieve this, but it will cause many more problems than it could ever solve.

0 Likes
Message 3 of 5

Neil-Star
Participant
Participant

When the window is max/min/restored is fine as it takes the panel with it. The issue is when the main application window is on screen at whatever size/location and you select a different program or explorer window which then appears on top of you inventor window, it's then that the panel is still visible.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

I do not know how you created that form, but most forms usually have a 'parent' or 'owner' specification, which may be what you need to set.  You can likely use the Application.MainFrameHWND property value for that (where 'Application' is the Inventor.Application object).  When you set the Inventor window as the form's parent/owner, than usually helps with similar situations.  If you were using an Inventor.DockableWindow, then you may need to change your 'dock' settings also, but that settings should not cause that kind of overlap on its own.  There is also usually one or more specifications &/or methods associated with most forms &/or controls, for specifying / settings if it is something like 'top level' or 'top most', such as Form.TopLevel or Form.TopMost.  Then of course there is how you show the form, which can determine if it is 'modal' or not' (Form.Show vs Form.ShowDialog).  When using one of those Show or ShowDialog methods, it is usually asking for an optional IWin32Window type input parameter.  I believe that you may have to create/use a custom 'wrapper' Class that implements that IWin32Window interface, which you can provide that property value from Inventor to it, so you specify that in that position.

Below is a custom Class block of code like that.  I'm sure I either found this on this forum somewhere, or on StackOverflow somewhere, but do not recall the actual link to that source anymore.

<Serializable>
Public Class HwndWrapper
	Implements IWin32Window
	Private ReadOnly m_hWnd As IntPtr
	
	Public Sub New(ByVal hWnd As IntPtr)
		m_hWnd = hWnd
	End Sub
	
	Public Sub New(ByVal hWnd As Integer)
		m_hWnd = CType(hWnd, IntPtr)
	End Sub
	
	Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
		Get
			Return m_hWnd
		End Get
	End Property
End Class

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

Neil-Star
Participant
Participant

Thanks for the response! loading the form with the windowwrapper and setting it to toplevel instead of topmost did the trick!

0 Likes