.NET

.NET

Reply
Active Contributor
btmcad
Posts: 31
Registered: ‎05-09-2007
Message 1 of 9 (985 Views)

A couple issues with vb.net and dialog boxes

985 Views, 8 Replies
07-26-2012 10:27 AM

I'm working on a program that involves one dialog box. The dialog box is launched from a class called myCommands using the following line of code:

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(dwgForm)

 

There are several text boxes and radio buttons on this dialog box. If the user forgets to fill out or select one of these, I would like a message box to display a message then revert back to the main dialog after selecting OK.

 

To do that, I added this code to the OK button:

 



 'check for size selection
        If rdbTitleA.Checked = False And rdbTitleB.Checked = False And rdbTitleC.Checked = False And rdbTitleD.Checked = False Then
            MsgBox("Please select a size to continue.")
            Exit Sub
        End If

        'check for initials
        If txtIni.Text = vbNullString Then
            MsgBox("Please enter your initials.")
            Exit Sub
        End If

        'check for folder selection
        If intFolder < 2 Then
            MsgBox("Please select an appropriate folder")
            Exit Sub
        End If

        'check for description
        If txtDesc1.Text = vbNullString Then
            MsgBox("Please type a description")
            Exit Sub
        End If

 Currently, when a user forgets to specify something in the dialog, the message box appears, but after selecting OK, the dialog box disappears, but the code from the myCommands class continues to execute.

What is the proper method to add in this type of error handling when working between a dialog box and a separate class?

 

I'm having another issue as well. After the user completes everything in the dialog box and selects OK, the program works properly. However, when the user selects that program again, within the same drawing, the dialog box reappears with all of the same info specified from the last time the program ran. Obviously, I want the dialog to start over clean, without all of the old data. What am I doing wrong?

 

Thanks

btm 



Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 2 of 9 (984 Views)

Re: A couple issues with vb.net and dialog boxes

07-26-2012 11:06 AM in reply to: btmcad

hi. if you done dispose the form you have the same data

 

For a clean form :

public Sub Test

dim f as WindowST

f = new WindowST

if f.showdialog = msgboxresult.ok then

.....

end if

f.dispose

f = nothing

end sub

 

so if you re launch this sub your new and dispose the form.

 

if you dont want to dispose so you need to clean your form when you show it  :

    Private Sub WindowST_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

    End Sub

you have that to :

Private Sub WindowST_Activated(.....

    End Sub

 

 

for the RadioButton use a groupbox and drop it the RB. With this only one RB can be checked.

 

and for you BpOk :

 

by default enabled = false

so you have to check you conf in the SelectionChanged or CheckedChanged

 

excample :

Private Sub RB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RBUtton.CheckedChanged


if RD.checked = true then BpOk.enabled = true
    End Sub

 

sorry for my english..

 

 

Active Contributor
btmcad
Posts: 31
Registered: ‎05-09-2007
Message 3 of 9 (949 Views)

Re: A couple issues with vb.net and dialog boxes

07-27-2012 09:40 AM in reply to: btmcad

I tried using dispose.

The program works fine on the first try. When I try to run the program again within the same drawing, I get a fatal error before the dialog box reappears.

I can't figure out what is causing this. I have used dispose in other VB.net programs to dispose of a dialog, and it worked fine.

 

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 4 of 9 (944 Views)

Re: A couple issues with vb.net and dialog boxes

07-27-2012 10:58 AM in reply to: btmcad

You should show the code where you show or re-show the form.  I assume you check for nothing, as in:

if dwgForm = nothing then define and show it.

 

You should also check for isdisposed because isdisposed is not the same as nothing. 

 

if dwgForm = nothing then define and show it, else if dwgForm.isdisposed, then define and show it.

 

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 5 of 9 (937 Views)

Re: A couple issues with vb.net and dialog boxes

07-27-2012 01:22 PM in reply to: fieldguy

here 2 example :

 

Private Sub BpRemplacement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BpRemplacement.Click
        Me.Visible = False
        Dim fen As New FenetreRemplaceBloc(FichierAffaire, ListeDesDefBLoc)
        fen.ShowDialog()
        fen.Dispose()
        fen = Nothing
        Me.Visible = True
    End Sub

 this one create a form and dispose when done.

I have to pass 2 data for the new form called FenetreRemplaceBloc

 

 

Private Sub MenuBlocAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuBlocAddG.Click, MenuBlocAddD.Click
        If IsNothing(FenetreBloc) = True Then
            FenetreBloc = New FenetreListingBloc
        ElseIf FenetreBloc.IsDisposed = True Then
            FenetreBloc = New FenetreListingBloc
        Else
            FenetreBloc.Close()
            FenetreBloc.Dispose()
            FenetreBloc = New FenetreListingBloc
        End If

        FenetreBloc.Show()
    End Sub

 

here the form FenetreBloc is a form of type FenetreListingBloc.

 

this form is not closed when i used it. So i check is is not nothing if it is nothing i initialize

if is IsDisposed a create a new one.

 

 

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 6 of 9 (936 Views)

Re: A couple issues with vb.net and dialog boxes

07-27-2012 01:24 PM in reply to: AubelecBE

i launch this 2 sub from a form

the first from a button event

the second from a ContextMenuStrip (MenuItem) event

Active Contributor
btmcad
Posts: 31
Registered: ‎05-09-2007
Message 7 of 9 (914 Views)

Re: A couple issues with vb.net and dialog boxes

07-30-2012 05:53 AM in reply to: btmcad

Here's the code I currently have. If I try to add dispose, or set to nothing, I get a fatal error.

So, I'm trying to determine the proper way to work with dialog boxes in .net. It seems there is very little info on this topic, related to Autocad, unless I'm looking  in the wrong places.

 

 

This block of code is the beginning of my program. It's a fairly simple program that inserts a new layout based on the sheet size selected from the dialog box. This code displays the dialog box, where the user makes a selection from the radio buttons. After selecting OK, the remaining part of the program runs which creates the new layout, and renumbers the titleblocks and layouts in the drawing file. The dialog box closes and the program finishes after the program runs one time, which is the way I want it to work.

It works as shown. I can run it as many times as I want within one drawing file, and it works everytime. However, each time it is run, the dialog displays the selection from the previous use. I would like the dialog box to be clean, each time the program starts.

As mentioned above, if I try to use dispose anywhere in the code, the program runs only one time. The next time I run the program within the same drawing, I get a fatal error.

 

Thanks

btm

 

 

 

 

 

<Assembly: CommandClass(GetType(AddLayout.MyCommands))> 

Namespace AddLayout

    
    Public Class MyCommands


        Public lytForm As New FrmLayout


        <CommandMethod("AddLayout", CommandFlags.modal + CommandFlags.session)> _
        Public Sub Main()
            Dim strLayoutName As String = vbNullString
            Dim strFileName As String = vbNullString


                Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(lytForm)

            
            'if cancel button is selected, end program
            If lytForm.DialogResult = System.Windows.Forms.DialogResult.Cancel Then
                Exit Sub
            End If




            'determine which sheet size radio button was selected


            If lytForm.rdbA.Checked = True Then
                strFileName = "C:\cad\templates\A-TITLE.DWT"
            ElseIf lytForm.rdbB.Checked = True Then
                strFileName = "C:\cad\templates\B-TITLE.DWT"
            ElseIf lytForm.rdbC.Checked = True Then
                strFileName = "C:\cad\templates\C-TITLE.DWT"
            ElseIf lytForm.rdbD.Checked = True Then
                strFileName = "C:\cad\templates\D-TITLE.DWT"
            End If


            strLayoutName = "Layout1"


            Dim revisionInf() As String = GetRevInfo()
            Dim titleblockInf() As String = GetTitleInfo()

            CopyLayoutFromTemplate(strFileName, strLayoutName)
            UpdateLayoutNumbersX()
            UpdateLayoutNumbers()
            UpdateSheetNumbers(titleblockInf, revisionInf)



        End Sub

 

 

 

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 8 of 9 (907 Views)

Re: A couple issues with vb.net and dialog boxes

07-30-2012 07:59 AM in reply to: btmcad

You should be able to reset all controls in the form load event.  Or you could try something like >>this< before you show it.

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 9 of 9 (897 Views)

Re: A couple issues with vb.net and dialog boxes

07-30-2012 09:43 AM in reply to: fieldguy

hi

 

i dont use .Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(lytForm)

 

byt i have try and it work for me

you have to do this :

 

if Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(lytForm) = Windows.Forms.DialogResult.OK Then

'determine which sheet size radio button was selected

If lytForm.rdbA.Checked = True Then
strFileName = "C:\cad\templates\A-TITLE.DWT"
ElseIf lytForm.rdbB.Checked = True Then
strFileName = "C:\cad\templates\B-TITLE.DWT"
ElseIf lytForm.rdbC.Checked = True Then
strFileName = "C:\cad\templates\C-TITLE.DWT"
ElseIf lytForm.rdbD.Checked = True Then
strFileName = "C:\cad\templates\D-TITLE.DWT"

End If


strLayoutName = "Layout1"


Dim revisionInf() As String = GetRevInfo()
Dim titleblockInf() As String = GetTitleInfo()

CopyLayoutFromTemplate(strFileName, strLayoutName)
UpdateLayoutNumbersX()
UpdateLayoutNumbers()
UpdateSheetNumbers(titleblockInf, revisionInf)

 

 

else

...

end if.

 

lytForm.dispose

 

 

 

 

 

. you use the commandflag.session so you need to use the lock before modify the database of autocad.

 

 

if you use the data from your form --> dont dispose before... only after.

 

for me, if you validate your form --> why dont move your code in the sub of you button ?.

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.