<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to center a modeless .Net Form in ArcMap in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475219#M12882</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Eric, if you follow the link in my signature to our company blog you'll find an entry that addresses the issue of showing modeless dialogs using .NET.&amp;nbsp; I'm not sure if it will correct the issue with centering the dialog so let me know how it goes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Jun 2010 11:31:59 GMT</pubDate>
    <dc:creator>NeilClemmons</dc:creator>
    <dc:date>2010-06-10T11:31:59Z</dc:date>
    <item>
      <title>How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475217#M12880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am able to setup the owner of the form so that the modeless dialog will minimize with ArcMap and stay ontop of ONLY ArcMap but I am unable to get a modeless dialog to center on ArcMap even when I have its StartupPosition set to CenterParent. I have tried the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
public override void onCreate(object hook) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pApplication = hook as IApplication
}

public override void OnClick() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IntPtr pIntPtr = new IntPtr(m_pApplication.hWnd);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyForm pMyForm = new MyForm();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pMyForm.Show((System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(pIntPrt);
}
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe the CenterParent property does not apply to a Modeless Form? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; -eric&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jun 2010 21:58:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475217#M12880</guid>
      <dc:creator>EricPaitz</dc:creator>
      <dc:date>2010-06-09T21:58:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475218#M12881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am able to setup the owner of the form so that the modeless dialog will minimize with ArcMap and stay ontop of ONLY ArcMap but I am unable to get a modeless dialog to center on ArcMap even when I have its StartupPosition set to CenterParent. I have tried the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
public override void onCreate(object hook) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_pApplication = hook as IApplication
}

public override void OnClick() {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IntPtr pIntPtr = new IntPtr(m_pApplication.hWnd);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyForm pMyForm = new MyForm();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pMyForm.Show((System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(pIntPrt);
}
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Maybe the CenterParent property does not apply to a Modeless Form? &lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; -eric&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;In your form properties, try setting the StartPositon to CenterScreen.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:00:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475218#M12881</guid>
      <dc:creator>RuchiraWelikala</dc:creator>
      <dc:date>2021-12-11T21:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475219#M12882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Eric, if you follow the link in my signature to our company blog you'll find an entry that addresses the issue of showing modeless dialogs using .NET.&amp;nbsp; I'm not sure if it will correct the issue with centering the dialog so let me know how it goes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Jun 2010 11:31:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475219#M12882</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2010-06-10T11:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475220#M12883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When I call my modeless form, I initialize its position to the center of the ArcMap window with the following code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;nbsp; Dim InitializeForm As New myProject.Processing
&amp;nbsp; InitializeForm.Form_Initialize(m_application)
&amp;nbsp; InitializeForm.Show(New Win32HWNDWrapper(m_application.hWnd))

the following is the code for the form

Public Class Processing

&amp;nbsp; Friend Sub Form_Initialize(ByVal m_Application As ESRI.ArcGIS.Framework.IApplication)

&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim pWinPos As ESRI.ArcGIS.Framework.IWindowPosition
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim CenterX As Short
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim CenterY As Short

&amp;nbsp;&amp;nbsp;&amp;nbsp; pWinPos = m_Application
&amp;nbsp;&amp;nbsp;&amp;nbsp; CenterX = (pWinPos.Width / 2) + pWinPos.Left
&amp;nbsp;&amp;nbsp;&amp;nbsp; CenterY = (pWinPos.Height / 2) + pWinPos.Top

&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.Left = CenterX - Me.Width / 2
&amp;nbsp;&amp;nbsp;&amp;nbsp; Me.Top = CenterY - Me.Height / 2

&amp;nbsp; End Sub

End Class

the following is the code for the class Win32HWNDWrapper

Public Class Win32HWNDWrapper
&amp;nbsp; Implements System.Windows.Forms.IWin32Window
&amp;nbsp; Private _hwnd As System.IntPtr

&amp;nbsp; Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle
&amp;nbsp;&amp;nbsp;&amp;nbsp; Get
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return _hwnd
&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get
&amp;nbsp; End Property

&amp;nbsp; Public Sub New(ByVal Handle As System.IntPtr)
&amp;nbsp;&amp;nbsp;&amp;nbsp; _hwnd = Handle
&amp;nbsp; End Sub
End Class
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:00:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475220#M12883</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2021-12-11T21:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475221#M12884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks everyone! Based on all the comments these are the two small classes I came up with. The first is just a way to wrap the IApplication and expose its Handle as a IWin32Window. This class can be used as the owner of the Show() method on a Form. That will deal with being ontop of the ArcMap application (only) and to minimize, maximize and restore with the ArcMap application too. The second class is a base class that any of my modeless forms can inherit from. Thanks again! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
public class IApplicationWrapper : System.Windows.Forms.IWin32Window {
 System.IntPtr m_pIntPtr;

 public IApplicationWrapper(IApplication pApplication) {
&amp;nbsp; m_pIntPtr = new IntPtr(pApplication.hWnd);
 }
 public IApplicationWrapper(SystemIntPtr pIntPtr) {
&amp;nbsp; m_pIntPtr = pIntPtr;
 }
 IntPtr System.Windows.Forms.IWin32Windwo.Handle {
&amp;nbsp; Get { return m_pIntPtr; }
 }
}

public class BaseForm : System.Windows.Forms.Form {
 private IApplication m_pApplication = null;
 
 ~BaseForm() {
&amp;nbsp; ESRI.ArcGIS.ADF.ComRelease.ReleaseCOMObject(m_pApplication);
 }

 protected override void OnLoad(EventArgs e) {
&amp;nbsp; if (m_pApplication != null) {
&amp;nbsp;&amp;nbsp; this.Left = (((((IWindowPosition)m_pApplication).Width / 2) + ((IWindowPosition)m_pApplication).Left) �?? (this.Width / 2));
&amp;nbsp;&amp;nbsp; this.Top = (((((IWindowPosition)m_pApplication).Height / 2) + ((IWindowPosition)m_pApplication).Top) �?? (this.Height / 2));
&amp;nbsp; }
&amp;nbsp; base.OnLoad(e);
 }
 public void Show(IApplication pApplication) {
&amp;nbsp; m_pApplication = pApplication
&amp;nbsp; this.Show(new IApplicationWrapper(pApplication));
 }
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:00:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475221#M12884</guid>
      <dc:creator>EricPaitz</dc:creator>
      <dc:date>2021-12-11T21:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to center a modeless .Net Form in ArcMap</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475222#M12885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've been trying to display a modeless form with the parent ArcMap form as the parent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This code works, but only the first time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IntPtr pPtr = new IntPtr(_application.hWnd);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;_parentWindow = (System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(pPtr);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; this.Show(_parentWindow);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Where _application is a valid reference to the current IApplication ArcMap object&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I close the dialog box and try to open it a second time, _parentWindow is always null.&amp;nbsp; Even though _application.hWnd &amp;gt; 0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any reason why this only works once?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I create a modeless dialog in ArcMap (C#) that the user can open and close and will always have ArcMap as the parent?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Aug 2010 19:27:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/how-to-center-a-modeless-net-form-in-arcmap/m-p/475222#M12885</guid>
      <dc:creator>RichardColeman</dc:creator>
      <dc:date>2010-08-05T19:27:58Z</dc:date>
    </item>
  </channel>
</rss>

