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?
Printable View
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?
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.
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.
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
Yes, you are right, that works but if you change frm.show to frm.showdialog then it wont work.
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.
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:)
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.Quote:
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?
Thank you, but its not what i am looking for.Quote:
Not Exactly what you were looking for ...
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.