|
-
Mar 7th, 2003, 05:03 PM
#1
Thread Starter
New Member
How to activate a form?
I know in VB 6.0 the code to activate a form was...
Private Sub cmdOK_Click ()
frmMainForm.Show
End Sub
How can I do the same in VB.Net?
Thanks
-
Mar 7th, 2003, 05:40 PM
#2
Dim frm As new Form1 ' <-Name of the form to load
frm.Show
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 7th, 2003, 05:42 PM
#3
PowerPoster
In .NET, in order to display a form, you first must create an instance of the class.
Code:
Dim frm As frmMain ' Allocate memory on the heap for for object
frm = New frmMain() ' Call class constructor to create and place object in heap
-
Mar 7th, 2003, 05:44 PM
#4
PowerPoster
[LGS] beat me to the punch..
-
Mar 7th, 2003, 08:20 PM
#5
Thread Starter
New Member
I tried the above code but it gave me an error. Something like, Value of .... can not be converted into a one dimensional array. Can any body break it down some more for me?
-
Mar 7th, 2003, 11:07 PM
#6
post the code you used (Cut / paste)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 7th, 2003, 11:48 PM
#7
Thread Starter
New Member
Here is the code I'm useing:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Click on button to open up Form2
Dim MainFrom As New Form2()
MainForm.show()
End Sub
-
Mar 7th, 2003, 11:54 PM
#8
PowerPoster
Dim MainForm As Form2
MainForm = New Form2()
MainForm.Show()
-
Mar 8th, 2003, 01:02 AM
#9
is Form2 called form2??
Dim frm As New Form1
frm.Show()
I dont get the () after the dim frm etc...hmmm
odd that it wouldnt work for you...
Hellswraith...if you do it like the code above.. you eliminate a whole step
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 8th, 2003, 03:05 AM
#10
He did that in two lines because if you use NEW in the declaration line then it has to check to see if it has been created everytime it access the object. At least that is the way it was in VB6, I'm not sure if .NET is smarter or not. I hope it is considering everything is an object. By setting it on the next line it removes that check thus speeding up access to the object.
-
Mar 8th, 2003, 10:12 AM
#11
PowerPoster
Edneeis,
Both ways of creating an object are equivalent in .NET. No longer is the additional overhead required when accessing an object this way.
-
Mar 8th, 2003, 02:02 PM
#12
Good because I stopped doing it in .NET and always found it a bit annoying.
-
Mar 9th, 2003, 11:31 AM
#13
Thread Starter
New Member
I tried to do this code in the form of Form 1 to load the Form2
Dim MainForm as Form2
(Then in the sub procedure)
Private Sub cmdOK_Click()
'Open up Form2
MainForm = New Form2
MainForm.Show
End Sub
This is exactly how I have it, and for some reason it gives me an error saying that "MainForm" is undeclared. Any body got any ideas?
-
Mar 9th, 2003, 01:41 PM
#14
Why do you have the declaration of MainForm outside of the sub?
Try this:
VB Code:
(Then in the sub procedure)
Private Sub cmdOK_Click()
'Open up Form2
Dim MainForm as New Form2()
MainForm.Show
End Sub
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
|