Solidworks 2020 VSTA User Form

248 Views Asked by At

I have created a empty SolidWorks macro, using VSTA 3.0 C# projet.

I tried that very simple example. It "works" but the process continue. I want to show a form. And wait for user to hit button to do tasks or quit.

    public void Main()
    {
        var frm = new Form1();
        frm.Show();

        return;
    }

    // The SldWorks swApp variable is pre-assigned for you.
    public SldWorks swApp;
2

There are 2 best solutions below

0
On BEST ANSWER

One way to do this is simply to add Application.Run() :

public void Main()
{
    var frm = new Form1();
    frm.Show();
    Application.Run(frm);

    return;
}

// The SldWorks swApp variable is pre-assigned for you.
public SldWorks swApp;
2
On

try this:

        myForm.ShowDialog();

        bool frmResult = (bool)myForm.DialogResult;

        if (frmResult == true)
        {
               //do your thing
        }
        else
        {
            //do nothing
            // MessageBox.Show("Canceled, nothing to do");
            return;
        }

Eddy