Select to view content in your preferred language

Form always on top behavior - vb.net

4511
6
Jump to solution
12-06-2012 03:32 AM
Corbinde_Bruin
Frequent Contributor
Hi all,

I'm programming an addin with a form and I'd like the form stay on top of ArcMap. The always on top property of the form makes it always on top of every window I have open.

I'd like it to behave like all the other ArcMap forms do:
Only the top most form when they have focus.
Always on top of ArcMap.
Never on top of other open programs that have focus.

Thank you,
cdebruin
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
You'll need to set the ArcMap window as the form's owner.  In the code below, m_application is a reference to the ArcMap application.

yourForm.Show(System.Windows.Forms.Control.FromHandle((IntPtr)m_application.hWnd));

View solution in original post

0 Kudos
6 Replies
NeilClemmons
Honored Contributor
You'll need to set the ArcMap window as the form's owner.  In the code below, m_application is a reference to the ArcMap application.

yourForm.Show(System.Windows.Forms.Control.FromHandle((IntPtr)m_application.hWnd));
0 Kudos
Corbinde_Bruin
Frequent Contributor
Thanks for responding Neil!

Translated to vb.net
yourForm.Show(System.Windows.Forms.Control.FromHandle(CType(m_application.hWnd, IntPtr)))


Thank you,
cdebruin
0 Kudos
KenBuja
MVP Esteemed Contributor
Here's how to do it for an addin in VB.Net

MyFormInstanceName.Show(System.Windows.Forms.Control.FromHandle(My.ArcMap.Application.hWnd))


Thanks to Jim Isbell for this
0 Kudos
Corbinde_Bruin
Frequent Contributor
Interestingly, the tab key stops working if I use .Show() instead of .ShowDialog(). It simply no longer navigates from control to control. Any way to make the tab stops work with .Show()? Any one else even aware of this problem?

Nevermind. I found this forum post:
http://forums.arcgis.com/threads/68761-Add-In-Tab-Key-problems?highlight=tab%2C+stops
0 Kudos
NeilClemmons
Honored Contributor
There are several ways to solve the problem.  One way is to add code to the form's key press events to handle such things as tabbing, mnemonics, accept/cancel, etc.  The drawback to this is that you have to add the code to every modeless form you create.  A better way is to create a blank form with the custom code, put it in a code library and have all of your forms inherit from it.  I'm attaching a code sample I wrote several years back that shows how you might do this.
0 Kudos
Corbinde_Bruin
Frequent Contributor
Thank you Neil,

Very helpful! I've never done anything like that before, but I was able to figure it out with the documentation you provided and some googling. I now have the Enhanced Modeless Dialogs working.

Thank you,
Corbin de Bruin
0 Kudos