Select to view content in your preferred language

User Form won't minimize with Arcmap

1198
4
Jump to solution
01-09-2017 10:21 AM
SteveCole
Honored Contributor

I'm sure this is a simple fix but I'm feeling dense and I've never figured it out. I have a .NET add-in that includes a Windows Form. For whatever reason, the Windows form will not minimize WITH Arcmap and stays "on top" of any application. What setting do I set to have the Windows form stay on top of Arcmap UI items but still minimize with Arcmap?

Here's my form on top of my browser while Arcmap is minimized.

Thanks!

Steve

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

There could be a potential answer here but as ESRI in their wisdom have removed the old forum and not migrated this fully the answer is lost to us. Unless ESRI read this and make it available (hint hint!)?

View solution in original post

4 Replies
DuncanHornby
MVP Notable Contributor

There could be a potential answer here but as ESRI in their wisdom have removed the old forum and not migrated this fully the answer is lost to us. Unless ESRI read this and make it available (hint hint!)?

DuncanHornby
MVP Notable Contributor

What is your code that shows the form? Do you set the owner property?

0 Kudos
SteveCole
Honored Contributor

The form is opened via a command button on a toolbar:

Imports ESRI.ArcGIS.ArcMapUI
Imports ESRI.ArcGIS.Carto
Imports System.Windows
Public Class cmdOpenClosureForm
 Inherits ESRI.ArcGIS.Desktop.AddIns.Button
Protected Overrides Sub OnClick()
 Try
 'Opens the Rd Closure Dialog
 Dim pMxDoc As IMxDocument
 Dim pActiveView As IActiveView
 Dim pGraphicsContainer As IGraphicsContainer
 Dim application = My.ArcMap.Application
 Dim isOpened As Boolean = False
 Dim theForm As frmAddSnoClosures = Nothing
'Make sure that the form isn't already open.
 For Each frm As Windows.Forms.Form In Windows.Forms.Application.OpenForms
 If TypeOf frm Is frmAddSnoClosures Then
 isOpened = True
 theForm = frm
 End If
 Next
If Not isOpened Then
 theForm = New frmAddSnoClosures
 End If
pMxDoc = application.Document
 pActiveView = pMxDoc.FocusMap
 pGraphicsContainer = pActiveView.GraphicsContainer
'Open the Form
 theForm.Show()
 pGraphicsContainer.DeleteAllElements()
pMxDoc = Nothing
 pActiveView = Nothing
 pGraphicsContainer = Nothing
 Catch ex As Exception
 globalErrorHandler(ex)
 End Try
 End Sub
End Class

I found the TopMost property that was previously mentioned and, once I changed the property from TRUE to FALSE and tried to rebuild my project, I got a series of errors which I now can't get rid of:

The blue highlighted line is an example of one of the lines throwing the new error. It's all related, I'm sure, but I'm not understanding it..

0 Kudos
SteveCole
Honored Contributor

The suggestion by Duncan Hornby‌ was the correct answer. Although the link from the old forum was bad, I think I found a thread that did make it over into GeoNet that had the correct solution. TopMost property did not solve the issue; rather, it was adding a little bit of code to the form's show method:

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

In my last post, I mentioned that playing with the TopMost property introduced a series of new errors into my project. That was a weird one but I finally figured out a way to correct it. On my user form, I use rectangleShapes to indicate to the user when they have successfully completed input steps in their workflow (when they complete a step, the shading behind that input turns green). RectangleShapes are part of Microsoft's Powerpack controls and, for whatever reason, the rectangleShape is a "private" control whereas every other form control used is public. I was trying to update the properties of the rectangleShape from the code from outside the scope of the form's codebase so that wasn't allowed. To work around this, I added several public properties to my form which allow me to do what I need to do:

Public Property toLocationTag() As String
     Get
          Return Me.fraToLoc.Tag
     End Get
     Set(value As String)
          Me.fraToLoc.Tag = value
     End Set
End Property

Public Property fromLocationVisibility() As Boolean
     Get
          Return Me.fraFromLoc.Visible
     End Get
     Set(value As Boolean)
          Me.fraFromLoc.Visible = value
     End Set
End Property‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Back on track. Yay.