.NET

Reply
Member
BuckeyeFanInFL76
Posts: 4
Registered: ‎04-11-2013
Message 1 of 4 (149 Views)
Accepted Solution

Newbie - Form1.vb and Mycommands.vb

149 Views, 3 Replies
04-15-2014 01:10 PM

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

 

 

 

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.

 

 

 

Mentor
mzakiralam
Posts: 231
Registered: ‎11-09-2012
Message 2 of 4 (120 Views)

Re: Newbie - Form1.vb and Mycommands.vb

04-16-2014 01:09 AM in reply to: BuckeyeFanInFL76

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?

Member
BuckeyeFanInFL76
Posts: 4
Registered: ‎04-11-2013
Message 3 of 4 (106 Views)

Re: Newbie - Form1.vb and Mycommands.vb

04-16-2014 05:39 AM in reply to: mzakiralam

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.

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 4 of 4 (99 Views)

Re: Newbie - Form1.vb and Mycommands.vb

04-16-2014 06:41 AM in reply to: BuckeyeFanInFL76

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.

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!