public override void onCreate(object hook) { m_pApplication = hook as IApplication } public override void OnClick() { IntPtr pIntPtr = new IntPtr(m_pApplication.hWnd); MyForm pMyForm = new MyForm(); pMyForm.Show((System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(pIntPrt); }
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:public override void onCreate(object hook) { m_pApplication = hook as IApplication } public override void OnClick() { IntPtr pIntPtr = new IntPtr(m_pApplication.hWnd); MyForm pMyForm = new MyForm(); pMyForm.Show((System.Windows.Forms.Form)System.Windows.Forms.Form.FromHandle(pIntPrt); }
Maybe the CenterParent property does not apply to a Modeless Form?
Thanks,
-eric
Dim InitializeForm As New myProject.Processing InitializeForm.Form_Initialize(m_application) InitializeForm.Show(New Win32HWNDWrapper(m_application.hWnd)) the following is the code for the form Public Class Processing Friend Sub Form_Initialize(ByVal m_Application As ESRI.ArcGIS.Framework.IApplication) Dim pWinPos As ESRI.ArcGIS.Framework.IWindowPosition Dim CenterX As Short Dim CenterY As Short pWinPos = m_Application CenterX = (pWinPos.Width / 2) + pWinPos.Left CenterY = (pWinPos.Height / 2) + pWinPos.Top Me.Left = CenterX - Me.Width / 2 Me.Top = CenterY - Me.Height / 2 End Sub End Class the following is the code for the class Win32HWNDWrapper Public Class Win32HWNDWrapper Implements System.Windows.Forms.IWin32Window Private _hwnd As System.IntPtr Public ReadOnly Property Handle() As System.IntPtr Implements System.Windows.Forms.IWin32Window.Handle Get Return _hwnd End Get End Property Public Sub New(ByVal Handle As System.IntPtr) _hwnd = Handle End Sub End Class
public class IApplicationWrapper : System.Windows.Forms.IWin32Window { System.IntPtr m_pIntPtr; public IApplicationWrapper(IApplication pApplication) { m_pIntPtr = new IntPtr(pApplication.hWnd); } public IApplicationWrapper(SystemIntPtr pIntPtr) { m_pIntPtr = pIntPtr; } IntPtr System.Windows.Forms.IWin32Windwo.Handle { Get { return m_pIntPtr; } } } public class BaseForm : System.Windows.Forms.Form { private IApplication m_pApplication = null; ~BaseForm() { ESRI.ArcGIS.ADF.ComRelease.ReleaseCOMObject(m_pApplication); } protected override void OnLoad(EventArgs e) { if (m_pApplication != null) { this.Left = (((((IWindowPosition)m_pApplication).Width / 2) + ((IWindowPosition)m_pApplication).Left) �?? (this.Width / 2)); this.Top = (((((IWindowPosition)m_pApplication).Height / 2) + ((IWindowPosition)m_pApplication).Top) �?? (this.Height / 2)); } base.OnLoad(e); } public void Show(IApplication pApplication) { m_pApplication = pApplication this.Show(new IApplicationWrapper(pApplication)); } }