Click to See Complete Forum and Search --> : How to close dialog forms during load event
Lunatic3
Dec 11th, 2002, 12:53 PM
During load event of dialog forms you can not close it using me.close or me.dialogresult=dialogresult.cancel or calling any closing event. How you would accomplish this?
Shook1s
Dec 11th, 2002, 02:24 PM
I may be way off here ...
Do you want it to be a modeless form?
If so use formname.show ... I think that is how you display a modeless form.
Lunatic3
Dec 11th, 2002, 02:34 PM
No, i dont want it to be modeless form. All i want is closing the form conditionally on load event of the from, but as far as i tested dialog forms does not close if the closing event is called during form load. the event is fired but the from does not close, so i guess i need something to abort the load.
Edneeis
Dec 11th, 2002, 03:15 PM
I don't know it works for me.
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Close()
End Sub
And the code that calls the form:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2()
frm.Show()
End Sub
Lunatic3
Dec 11th, 2002, 03:21 PM
Yes, you are right, that works but if you change frm.show to frm.showdialog then it wont work.
Edneeis
Dec 11th, 2002, 04:44 PM
Ok I see what you are saying now, hmm that is strange.
Couldn't you have a function on the form that returns T/F whether or not the form needs to be loaded? Then you can call that function and only if its true would you show the form otherwise not?
If there isn't anything realted to that specific instance then you could make it a shared function and not even have to make an instance of the form to call it.
flog3941
Dec 11th, 2002, 07:26 PM
This on form1 "Button1" is whatever control your using to disply form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form2 As New Form2()
Me.Visible = False
form2.ShowDialog()
Dispose()
End Sub
It hides form1 and then disposes it once form2 is closed!
Not Exactly what you were looking for but I hope it works:)
Lunatic3
Dec 12th, 2002, 09:07 AM
Couldn't you have a function on the form that returns T/F whether or not the form needs to be loaded? Then you can call that function and only if its true would you show the form otherwise not?
Well, that function retruns some values from a database and if i want to have it on parent form then i have to go through making connections, dataset,... which is not desirable cause the same connection will be used on the dialog form too.
Not Exactly what you were looking for ...
Thank you, but its not what i am looking for.
Edneeis
Dec 12th, 2002, 10:12 AM
Actually I mean the dialog form. The form can be loaded and not shown and since the problem with closing only comes when the form is shown as a dialog then it would close fine if its not been shown at all yet.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.