Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to end FORM2 after Form.ShowDialog 1

Status
Not open for further replies.

WordTechinc

Programmer
Sep 4, 2009
38
0
0
FORM1 need to get result from FORM2 and keep run next step in FORM1. So I used .showdialog() instead of .show(). The problem is I get result from FORM2 but looks like FORM2 still running. FORM2 looks like hide. How to end FORM2 after .showdialog()? I am a beginner. I read article about dislogresult. I didn't understand how this works. It says create Button(is this command button?) on Form2 for DialogResult. How to do it? How this works between FORM1 and FORM2.



from FORM1;


If dtJobDetailsMileRadius.Rows.Count > 0 Then

If objFrmMileRadius.Visible = False Then
objFrmMileRadius.Dispose()
objFrmMileRadius = New FrmMileRadius(txtJobNo.Text.Trim)
End If

objFrmMileRadius.ShowInTaskbar = True
objFrmMileRadius.dtMileRadiusLocations = dtJobDetailsMileRadius
objFrmMileRadius.ShowDialog()


objFrmMileRadius.Visible = False
objFrmMileRadius.Enabled = False
objFrmMileRadius.ShowInTaskbar = False
objFrmMileRadius.Dispose()
objFrmMileRadius.Close()
Else
CMDSMsgBox("No MileRadius method exist in job details.")
End If

If BoResetFlagMRind = True Then
Call Sub1
Call Sub2
End if


FORM2;

Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click, cmdFormClose.Click

If BoRadiusFlagMRind = True Then
BoResetFlagMRind = True
Me.Dispose()
Else
BoResetFlagMRind = False
End If


Me.Close()

End Sub

 
hi,

what happens is on form1 you open form2 with the show dialog line then in your code you look for the dialog result from form2:

Code:
form2.showdialog
If form2.ShowDialog = Windows.Forms.DialogResult.OK Then
  'do whatever you want to do with the form2 stuff
  'example
  mytextbox.text = Form2.Text1.text
else
  msgbox("user aborted operation")
end if

In the code in form2 you need to set the dialog result of the form to say OK or Cancel etc. when you are finshed with it this is when the form will close. (it will still be queryible from the sub that opened it until that sub has finished processing but will disappear to your users)
In this example we'll do a form validation
Code:
Sub ValidateForm()
  If trim(MyTextbox.Text) <> "" then
    'closes form and returns a result of OK 
    Me.DialogResult = Windows.Forms.DialogResult.OK
  Else
    'close form returning a cancel
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
  End if  
End Sub
 
Thank you Waddlellg. It works after change with your IF logic.

on FORM1;

FORM2.Showdialog.Dialogresult.OK - this gives error

I changed;

IF FORM2.Showdialog = Windows.Forms.DialogResult.OK then
sub1
Else
FORM2.Dispose
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top