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:
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?
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
f = nothing
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
you have that to :
Private Sub WindowST_Activated(.....
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
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
sorry for my english..
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.
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.
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.
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.
<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.S
howModalDialog(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
i dont use .Autodesk.AutoCAD.ApplicationServices.Application.
byt i have try and it work for me
you have to do this :
'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"
strLayoutName = "Layout1"
Dim revisionInf() As String = GetRevInfo()
Dim titleblockInf() As String = GetTitleInfo()
. 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 ?.
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register
Start with some of our most frequented solutions to get help installing your software.