MVP Pattern

Depending on the complexity of the user interface it can be worthwhile using an MVP type pattern
Before you can implement this pattern you will need to add the necessary Framework Classes


System.Windows.Forms.MessageBox.Show(ex.Message);


Displaying Modal Form

Add the following code to the Constants.cs file

public struct Structure_RECT 
{
    public int Left;
    public int Top;
    public int Right;
    public int Bottom;
}

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool GetWindowRect(
    System.IntPtr hWnd,
    ref Constants.Structure_RECT rect);

Add the following code to the Code.cs file

public class Code 
{
public static void Method_DisplayForm
{
Constants.Structure_RECT oRect;
System.IntPtr ohandle;
System.Windows.Forms.NativeWindow nativeWindow;

oRect = new Constants.Structure_RECT();
ohandle = Code.Method_HandleGet(Globals.ThisAddIn.Application);
nativeWindow = new System.Windows.Forms.NativeWindow();
nativeWindow.AssignHandle(ohandle);
Constants.GetWindowRect(ohandle, ref oRect);
nativeWindow.ReleaseHandle();

MyForm_Model model = new MyForm_Model();

MyForm_View view = new MyForm_View();
view.Property_WindowCenterX = oRect.Left + (oRect.Right - oRect.Left) / 2;
view.Property_WindowCenterY = oRect.Top + (oRect.Bottom - oRect.Top) / 2;
view.Property_Caption = "my new caption";
view.Method_Initialize();

MyForm_Presenter presenter = new MyForm_Presenter(model, view);

view.ShowDialog();
}
}

Add the following assembly reference: "System.Windows.Forms"
Right mouse click on References, in the Solution Explorer window
SS
add "Method_DisplayForm()"


this is the handle for the Microsoft Application window
in an Excel VSTO Add-in this can be accessed from the Application object



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