|
-
Dec 11th, 2002, 01:53 PM
#1
Thread Starter
Frenzied Member
How to close dialog forms during load event
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?
-
Dec 11th, 2002, 03:24 PM
#2
Lively Member
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.
-
Dec 11th, 2002, 03:34 PM
#3
Thread Starter
Frenzied Member
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.
-
Dec 11th, 2002, 04:15 PM
#4
I don't know it works for me.
VB Code:
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:
VB Code:
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
-
Dec 11th, 2002, 04:21 PM
#5
Thread Starter
Frenzied Member
Yes, you are right, that works but if you change frm.show to frm.showdialog then it wont work.
-
Dec 11th, 2002, 05:44 PM
#6
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.
-
Dec 11th, 2002, 08:26 PM
#7
Lively Member
This Works
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
-
Dec 12th, 2002, 10:07 AM
#8
Thread Starter
Frenzied Member
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.
-
Dec 12th, 2002, 11:12 AM
#9
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|