Results 1 to 9 of 9

Thread: How to close dialog forms during load event

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    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?

  2. #2
    Lively Member
    Join Date
    Dec 2000
    Location
    Toronto, Canada
    Posts
    112
    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I don't know it works for me.

    VB Code:
    1. Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Me.Close()
    3.     End Sub

    And the code that calls the form:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim frm As New Form2()
    3.         frm.Show()
    4.     End Sub

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Yes, you are right, that works but if you change frm.show to frm.showdialog then it wont work.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  7. #7
    Lively Member flog3941's Avatar
    Join Date
    Nov 2002
    Posts
    123

    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

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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
  •  



Click Here to Expand Forum to Full Width