.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Newbie - Form1.vb and Mycommands.vb

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
BuckeyeFanInFL76
475 Views, 3 Replies

Newbie - Form1.vb and Mycommands.vb

I have a question on how to exit a program with an Exit button.  I have all my personalized commands in the myCommands.vb file.  I also have a form1.vb file I want to use as a user interface.  On my form there is a button to continue the program and there is a button to exit the program.

 

Below is the Form1 coding:

Public Class Form1

    Private Sub bExit_Click(sender As Object, e As EventArgs) Handles bExit.Click
        Stop
    End Sub

    Private Sub bGo_Click(sender As Object, e As EventArgs) Handles bGo.Click
        Me.Hide()

    End Sub
End Class

 Below is the coding that calls form1 from the myCommands file:

        <CommandMethod("BNOT")>
        Sub BuildNotification()
            Dim frm1 As New Form1
            frm1.Show()
            
            (the rest of the program.......)
            
            frm1.Dispose()
        End Sub

 The command works properly when the "Go" button (the button that causes the program to proceed) is clicked.  The problem is that when the Exit button is clicked, the program continues.  I see that the Stop command in the exit button only works on form1.  My question is how can I get form1 to pass the stop/exit command back to the mycommands file to stop the program altogether?

 

Thank you for your time,

Jarrod

 

 

 

3 REPLIES 3
Message 2 of 4

Hi,

your question is not clear to me. which program you want to exit? AutoCAD or just to close the winform. to exit a form just use Me.Close. or to exit autocad you have to do it diffently.

 

Another thing I have noticed in your code. In autoCAD you should not use frm1.show to call a winform. This is not recommended and might not work properly in autocad. you should use the standard way to call a form which is like below

Application.ShowModaldialog(frm1)

  I have a question why are you using frm1.dispose after calling it?

Message 3 of 4

mzakiralam,

When I click exit button on the form1, I would like it to close form1 which I did with the me.dispose() command in the exit button click event.  I would also like it to exit the "BNOT" command that called form1 and it to stop executing the Sub BuildNotification() subroutine.  Autocad needs to stay open, I just want to cancel the "BNOT" command.

 

Thanks for the tip on calling form1 via Application.ShowModaldialog(frm1).  I have updated my code.

 

Last, I call form1.dispose() after the code for the command has executed.  This is how I imagine to properly cleanup the program before it ends.  Whether it is right or now, I am not sure.

 

Thank you again for your time.

Message 4 of 4

It looks like you need a bit more study on how Windows Form is created/displayed/disposed.

 

A form/dialog box can be shown as modeless or modal. Depending on which way to show it, the Form.Close() (or clicking the "x" button at upper right corner) behaves differently. For modeless, Form.Close() disposes the form, while for modal form, Form.Close() only hide the form, and only be disposed when Dispose() is called explicitly or implicitly (say, in Using... block).

 

Also, if you display form/dialog in AutoCAD, you should use Autodesk.AutoCAD.ApplicationServices.Application.ShowModeless/ModalDialog(), instead of Form.Show()/ShowDialog().

 

In AutoCAD, if you show a modeless form in a command method, after the form shows, the command continues to its end; while if the form is shown as modal, the command is held and only continues after the modal form is dismissed.

 

In most cases, w form in AutoCAD is shown as nodal because a command/process needs to collect some user inputs before it can carry on. depening on user's input, when the form is dismissed, the command either continue for further process or exit.

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost