xarial / xcad

Framework for developing CAD applications for SOLIDWORKS, including add-ins, stand-alone applications, macro features, property manager pages, etc.
https://xcad.net
MIT License
126 stars 25 forks source link

Create WinForm popup in a different class #120

Open andrMollo opened 7 months ago

andrMollo commented 7 months ago

Following you example I was able to show a WinForm as popup in an add-in built with xCAD 0.7.12.

Now I would like to show the form as popup from a class different from the main add-in class library. Is it possibile?

I have the main class library AddInClass:

using AddInLibrary.UI;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Xarial.XCad.Base.Attributes;
using Xarial.XCad.SolidWorks;
using Xarial.XCad.UI.Commands;

namespace AddInLibrary
{
    [ComVisible(true)]
    [Title("Test Add-In")]
    [Description("An Add-In for test purpose")]
    public class AddInClass : SwAddInEx
    {
        [Title("Test Add-In")]
        [Description("Test commands")]
        public enum Commands_e
        {
            [Title("Show form")]
            [Description("Show a windows form")]
            FormCommand,
            [Title("Show form2")]
            [Description("Show form from class")]
            FormCommandExt
        }

        public override void OnConnect()
        {
            CommandManager.AddCommandGroup<Commands_e>().CommandClick += OnCommandClick;
        }

        private void OnCommandClick(Commands_e command)
        {
            switch (command)
            {
                case Commands_e.FormCommand:
                    var winFormPopUpWnd = this.CreatePopupWindow<TestWinForm>();
                    winFormPopUpWnd.ShowDialog();
                    break;
                case Commands_e.FormCommandExt:
                    ShowFormClass.ShowWinForm();
                    break;
            }
        }
    }
}

The another class ShowFormClass:

namespace AddInLibrary
{
    internal class ShowFormClass
    {
        public static void ShowWinForm()
        {

        }
    }
}

I would like the ShowWinForm method to open TestWinForm as a popup.

A link to a test repo.

Thanks in advance.

andrMollo commented 7 months ago

Hi! I was able to show the winform using the ShowDialog method and seems to work fine for my purposes. Are there any particular benefit to use CreatePopupWindow instead?