Making form modeless in VB.net/SW VSTA

I have written a macro in SW VSTA and would like to make the form modeless so that parts can be selected in the SW window while the program is running. In the main module I am using Form1.ShowDialog() to show the form but I can not select anything in SW. Using the VB6 Form1.Show 0 does not work nor does Application.Run(Form1).

How does a person make the form modeless?

Dan Miel

SW 2009

SolidworksApi macros
Answers 15
JC
JC 2009-10-19 Best Answer

Form1.ShowDialog()  will stop the code untill the form is close  this is for a dialog type window

use Form1.Show() this is show the form but then continue in the code

DM
DM 2009-10-19

Jacob

When I try to use Form1.show the form will flicker on for a moment then disappear. I believe that this as caused because the form is declared as form 1 in the module, then when the form shows it loses the declaration.

In this example the form flickers on and off

Dim Form1 as New Form1

Form1.show()

In this example the program errors

Dim Form1 as New Form1

Form1.show(0)

Dan
JC
JC 2009-10-19


Dim Form1 As Form1
Set Form1 = New Form1
Form1.Show (0)

DM
DM 2009-10-19
This didn’t work. VSTA is the 2009 SolidWorks macros and uses the .Net syntax so the “Set” word is not used and "Form.Show" doesn’t work the way it did in VB6 or VBA.

Dan

JC
JC 2009-10-19
DM
DM 2009-10-20

The Form1(Me) starts a form modeless if there is a form activated already and a form is started from the first form. In SW VSTA I can not find an option to start the program from a form like you can in .Net. It looks like I need to start it from the module.

I can not figure out how to start a modeless form from a module. I have attached a sample program that creates forms but the first form “Form0” is model not modeless, the rest of the forms are modeless.

Thanks for your input.

Dan Miel

TS
TS 2009-10-20

Howdy,

I was just looking for the same thing. I discovered the following:

Required in the General Declarations:

Imports System.Windows.Forms.Form

Then either of the following should work in the main() or starting sub:

' show form
frm_FstDrw.ShowDialog() 'show nonmodal
frm_FstDrw.Show() 'show modal

Hope this helps

DM
DM 2009-10-21

I found that on my machines, using Form1.Show() will not show my form when I debug the program. After I build the program and connect a button to run the dll file the form shows and I can select parts in the SW window.

When I tried using Application.Run(Form1) it gave me an error me the error "The name Application is not declared" until I imported System.Windows.Forms then in debug the form will show but I can not select parts in SW. After doing a build and using the dll file the form will show and I can select parts.

Is anyone finding similar behavior or am I still missing something?

Tobin. Thanks for the hint on Import Forms.

Dan Miel

TS
TS 2009-10-21

Howdy,

I've attached a new copy of the SWFormMacro.zip with a few changes.

On my machine it alows me to select SW objects while the form is showing in Debug mode.


Hope this helps

DM
DM 2009-10-21

This macro does the same thing that my tries have done. When I debug the form flashes on the screen and disappears. If I build it and then run the dll the form stays and I can select parts in SW as expected. I guess I'll be looking at my machines to see what is goofy.

Thanks

Dan

SW 2009

SF
SF 2009-10-26
JJ
JJ 2012-02-16

Those links are broken

SF
SF 2013-07-16

Dear Dan Miel,

I have got stuck in the same problem for such a long long time. However, I recently get the good new from the senior programmer about resolution. Please do this things

-First, we have to get the 'SolidWorksMacroStartup.cs' open by right click the partial class name 'SolidWorksMacro' shown below\

-Choose 'Find All References', we will get the reference list and, in the list choose the file shown below

-When the 'SolidWorksMacroStartup.cs' open goto the line shown below and comment it out

-Compile and get the form shown modeless!

Credit: P' Nin songsak@z-byte.com

comment imagecomment imagecomment imagecomment imagecomment imagecomment image
SF
SF 2014-05-03

'btnOK : first Create a Button in your form and set its name to btnOK

        Dim frm As Form1 = New Form1

        frm.Show()

        While frm.btnOK.Disposing

            ':-)

        End While

SF
SF 2014-05-11

use this :

Imports System.IO'#######

Imports SolidWorks.Interop.swconst

        swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swStopDebuggingVstaOnExit, False)

        Dim f As Form1 = New Form1()

        f.Show()

        'System.Windows.Forms.Application.Run(f)