Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create WinForm popup in a different class #120

Open
andrMollo opened this issue Dec 13, 2023 · 1 comment
Open

Create WinForm popup in a different class #120

andrMollo opened this issue Dec 13, 2023 · 1 comment
Assignees

Comments

@andrMollo
Copy link
Contributor

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
Copy link
Contributor Author

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?

@artem1t artem1t self-assigned this Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants