Owner

If you are displaying a message box inside Excel, then Excel is the owner by default.
For this reason you do not need to use the owner parameter inside a VSTO add-in.
Assigning the owner parameter has nothing to do with displaying in the Centre of Parent.

public static Microsoft.Office.Interop.Excel.Application gEXCELAPPLICATION; 

public class Win32Window : System.Windows.Forms.IWin32Window 
{
   private IntPtr _handle;
   public Win32Window(System.IntPtr oHandle)
   {
      this._handle = oHandle;
   }
   public Win32Window(int oHandle)
   {
      this._handle = new System.IntPtr(oHandle);
   }
   System.IntPtr System.Windows.Forms.IWin32Window.Handle
   {
      get { return this._handle; }
   }
}

System.Windows.Forms.IWin32Window owner; 
owner = new Win32Window(Constants.gEXCELAPPLICATION.Hwnd);

System.Windows.Forms.MessageBox.Show(owner,
    sText, sCaption,
    System.Windows.Forms.MessageBoxButtons.OK,
    System.Windows.Forms.MessageBoxIcon.Exclamation);

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext