Select to view content in your preferred language

How to keep a Windows Form pop-up in front of ArcGIS Pro at all times?

2457
3
Jump to solution
07-01-2021 10:33 PM
anonymous_geographer
Frequent Contributor

Hello everyone,

I'm making the transition from ArcObjects over to ArcGIS Pro SDK (C#). I'm enjoying the learning experience so far, but I've hit a snag with a feature I'm trying to implement. Once a tool within my Pro dockpane's listbox has been executed, I want it to open a Windows Form center screen and stay in front of the ArcGIS Pro application at all times while the form is open (i.e. the form doesn't disappear behind the application if the user navigates back to their open map).

So far, I have the following code working fine when the form is launched:

 

 

gui_tool_polygon_overlaps tool_gui_polygon_overlaps = new gui_tool_polygon_overlaps();
tool_gui_polygon_overlaps.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
tool_gui_polygon_overlaps.Show();

 

 

 
However, I can't seem to locate the piece of code needed to keep the pop-up form in front of Pro.

In ArcObjects, I would use this:

 

 

gui_tool_polygon_overlaps tool_gui_polygon_overlaps = new gui_tool_polygon_overlaps();
tool_gui_polygon_overlaps.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
tool_gui_polygon_overlaps.Show(Control.FromHandle((IntPtr)ArcMap.Application.hWnd));

 

 


Can anyone tell me what the Pro SDK equivalent of...

 

 

Control.FromHandle((IntPtr)ArcMap.Application.hWnd)

 

 

 ...would be? Or is there a new, improved way to accomplish this task that I may be overlooking?

I was attempting to test the ".Owner" property of the form as well, but was struggling to figure out what to set it to specifically (if that's even the right course of action here).

Thanks for any insight!

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I would recommend to use a ProWindow instead of a Windows Form.

A ProWindow can stay on top with this:

myProWindow.Owner = FrameworkApplication.Current.MainWindow;

I haven't tried this, but  you should be able to get your required functionality by using something like this:

NativeWindow ownerWindow = new NativeWindow();
ownerWindow.AssignHandle((new WindowInteropHelper(FrameworkApplication.Current.MainWindow)).Handle);
winForm.Show(ownerWindow);

 

View solution in original post

3 Replies
anonymous_geographer
Frequent Contributor

After some trial and error, I stumbled upon a band-aid solution for now:

 

gui_tool_polygon_overlaps tool_gui_polygon_overlaps = new gui_tool_polygon_overlaps();
tool_gui_polygon_overlaps.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
tool_gui_polygon_overlaps.TopMost = true;
tool_gui_polygon_overlaps.Show();

 

However, this will cause the window to display in front of every open application (browser, email, etc.), which is not ideal at all. I would prefer this to be linked only to the Pro application/window itself.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I would recommend to use a ProWindow instead of a Windows Form.

A ProWindow can stay on top with this:

myProWindow.Owner = FrameworkApplication.Current.MainWindow;

I haven't tried this, but  you should be able to get your required functionality by using something like this:

NativeWindow ownerWindow = new NativeWindow();
ownerWindow.AssignHandle((new WindowInteropHelper(FrameworkApplication.Current.MainWindow)).Handle);
winForm.Show(ownerWindow);

 

anonymous_geographer
Frequent Contributor

Wolf, I appreciate your response! I can confirm that I was able to get the desired behavior with your feedback. After adding assembly references for System.Windows.Forms, System.Windows.Interop, and ArcGIS.Desktop.Framework, the following works perfectly:

gui_tool_polygon_overlaps tool_gui_polygon_overlaps = new gui_tool_polygon_overlaps();
tool_gui_polygon_overlaps.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
NativeWindow ownerWindow = new NativeWindow();
ownerWindow.AssignHandle((new WindowInteropHelper(FrameworkApplication.Current.MainWindow)).Handle);
tool_gui_polygon_overlaps.Show(ownerWindow);

 
This is the first Form I've incorporated into my dockpane's listbox, so I will experiment with and test the ProWindow next! 👍

0 Kudos