|
-
Sep 14th, 2005, 12:46 AM
#1
Thread Starter
Lively Member
[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 ?
-
Sep 14th, 2005, 01:26 AM
#2
Fanatic Member
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:
Dim f2 As New Form2
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If f2.IsDisposed = True Then
f2 = New Form2
f2.Show()
Else
f2.Show()
f2.Activate()
End If
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! 
-
Sep 14th, 2005, 09:41 PM
#3
Thread Starter
Lively Member
Re: Opening a new form
 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:
Dim f2 As New Form2
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If f2.IsDisposed = True Then
f2 = New Form2
f2.Show()
Else
f2.Show()
f2.Activate()
End If
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 ?
-
Sep 14th, 2005, 10:03 PM
#4
Fanatic Member
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! 
-
Sep 14th, 2005, 10:10 PM
#5
Thread Starter
Lively Member
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 ?
-
Sep 14th, 2005, 10:17 PM
#6
Fanatic Member
Re: Opening a new form
well then,...
VB Code:
Dim f2 As New Form2
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
f2.Show()
f2.Activate()
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! 
-
Sep 14th, 2005, 10:23 PM
#7
Fanatic Member
Re: Opening a new form
I think this would be even better for refreshing the form...
VB Code:
Dim f2 As New Form2
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If f2.IsDisposed = False Then
f2.Dispose()
f2 = New Form2
f2.Show()
Else
f2 = New Form2
f2.Show()
End If
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! 
-
Sep 14th, 2005, 10:55 PM
#8
Thread Starter
Lively Member
Re: Opening a new form
Now, this works! thks man!
sOMEONE'S gONNA dO iT, wHY nOT yOU ?
-
Sep 15th, 2005, 12:15 AM
#9
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
|