Results 1 to 9 of 9

Thread: [RESOLVED] Opening a new form

  1. #1

    Thread Starter
    Lively Member FYRe's Avatar
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    102

    Resolved [RESOLVED] Opening a new form

    Hi All,

    I have 2 forms, FormA, FormB.
    I'd like to open FormB upon clicking a button, btn_Match.

    I used the following method to display FormB:

    Dim nwfrm As New FormB
    nwfrm.Show()



    It's is successful, I clicked the button, FormB appears.
    But then, if I did not close FormB, I clicked btn_Match again, a 2nd FormB appears.

    I do not want this to happen; what I wanted is that when I clicked btn_Match again and again, it refreshes FormB, WITHOUT opening another FormB.


    Regards,
    FYRe
    sOMEONE'S gONNA dO iT, wHY nOT yOU ?

  2. #2
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Opening a new form

    Hi Fyre..
    here is the way to check whether the form is closed or hidden and perform the action according to it
    VB Code:
    1. Dim f2 As New Form2
    2.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         If f2.IsDisposed = True Then
    4.             f2 = New Form2
    5.             f2.Show()
    6.         Else
    7.             f2.Show()
    8.             f2.Activate()
    9.         End If
    10.     End Sub
    Hope it helps

    Edit:Heyy,there was someone who posted here before me...It dissapeared after I posted my message.That was a cool magic. Maybe they deleted it.
    Last edited by uniquegodwin; Sep 14th, 2005 at 01:36 AM.
    Godwin

    Help someone else with what someone helped you!

  3. #3

    Thread Starter
    Lively Member FYRe's Avatar
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    102

    Re: Opening a new form

    Quote Originally Posted by uniquegodwin
    Hi Fyre..
    here is the way to check whether the form is closed or hidden and perform the action according to it
    VB Code:
    1. Dim f2 As New Form2
    2.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         If f2.IsDisposed = True Then
    4.             f2 = New Form2
    5.             f2.Show()
    6.         Else
    7.             f2.Show()
    8.             f2.Activate()
    9.         End If
    10.     End Sub
    Hope it helps

    Edit:Heyy,there was someone who posted here before me...It dissapeared after I posted my message.That was a cool magic. Maybe they deleted it.
    UniqueGodwin, your lines of codes seems to be partially correct.
    What if I already initially opened my Form2 ? If I click btn_Match, wouldn't it open a new Form2; that means I have 2 of Form2. That's not what I wanted.

    I wanted there to be only one of Form2 no matter how many times you click on the button. At the same time, when you click, I want to Refresh Form2.

    So, I suppose the "else" part of your codes are wrong ?
    sOMEONE'S gONNA dO iT, wHY nOT yOU ?

  4. #4
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Opening a new form

    Fyre...if you already opened your form and "CLOSED" it....then, a new form will open since the old form is "DISPOSED" (Destroyed)...

    but,if you have a form open and didnt close it,then,the code would open a new form..(It doesnt exist in the memory,so creates one)

    Ill tell it again shortly...IF A FORM IS ALREADY OPEN,IT ACTIVATES THE FORM,IF THE FORM IS CLOSED(DISPOSED) THEN IT OPENS A NEW FORM,COS,THERES NO FORM AT ALL NOW TO SHOW,SO IT CREATES.
    This is the exact thing you need according to what you've asked...Try the code and see it work.
    Godwin

    Help someone else with what someone helped you!

  5. #5

    Thread Starter
    Lively Member FYRe's Avatar
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    102

    Re: Opening a new form

    But, my current situation now is, I do not want to close Form2, I just want Form2 to remian and refreshes itself when I click btn_Match.
    sOMEONE'S gONNA dO iT, wHY nOT yOU ?

  6. #6
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Opening a new form

    well then,...
    VB Code:
    1. Dim f2 As New Form2
    2.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         f2.Show()
    4.         f2.Activate()
    5.     End Sub
    Thats all you need to do for that..Someone posted this same code before I posted my 1st post...but,they deleted it..I dont know why..
    But,this thing will give an error if you click the button after closing the form
    Godwin

    Help someone else with what someone helped you!

  7. #7
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: Opening a new form

    I think this would be even better for refreshing the form...
    VB Code:
    1. Dim f2 As New Form2
    2.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         If f2.IsDisposed = False Then
    4.             f2.Dispose()
    5.             f2 = New Form2
    6.             f2.Show()
    7.         Else
    8.             f2 = New Form2
    9.             f2.Show()
    10.         End If
    11.  
    12.     End Sub
    This will close the form if a form is open and open the same form again so all its values are gone..its the same form,but,old is gone and new form
    Godwin

    Help someone else with what someone helped you!

  8. #8

    Thread Starter
    Lively Member FYRe's Avatar
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    102

    Re: Opening a new form

    Now, this works! thks man!
    sOMEONE'S gONNA dO iT, wHY nOT yOU ?

  9. #9
    Fanatic Member uniquegodwin's Avatar
    Join Date
    Jul 2005
    Location
    Chennai,India
    Posts
    694

    Re: [RESOLVED] Opening a new form

    hehe,Alas,one code from me works for u
    Thanks
    Godwin

    Help someone else with what someone helped you!

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