|
-
Jun 22nd, 2005, 11:58 AM
#1
Thread Starter
Junior Member
How to open a Form??
Very basic...
I'm brand new to Visual Basic.NET and trying to figure it out (making the first "Hello World")
How does I operate forms like in VB6:
VB Code:
Private Sub Command1_Click()
Form2.Show
End Sub
VB Code:
Private Sub Command2_Click()
Form2.Hide
End Sub
Claus
-
Jun 22nd, 2005, 12:08 PM
#2
Re: How to open a Form??
You can show a form several ways. This is to show it modally.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oForm As New Form2
oForm2.ShowDialog
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 22nd, 2005, 12:10 PM
#3
Member
Re: How to open a Form??
oform2.showdialog() will make it so the user must finish with that form before moving on.
oform2.show() will just make it appear.
- Josh
-
Jun 22nd, 2005, 01:45 PM
#4
Member
Re: How to open a Form??
The main difference is that you have to set a variable to the form, and then access the forms properties through that variable. The form can also be hidden in VB .NET, but I'm not sure if you want to hide it, or close it. Closing it will give you back resources. Hiding keeps the resources in use and the form still loaded in memory and accessible through code. If you're not going to use the form anytime soon or it's a one shot, best close it. If you're going to keep using it but don't want it visible all the time then hide would probably be better so you're not constantly opening and closing it.
The above code could be written like this:
VB Code:
Dim myForm as new Form2
Private Sub Command1_Click()
myForm.ShowDialog
End Sub
VB Code:
Private Sub Command2_Click()
myForm.close ' or myForm.hide
End Sub
-
Jun 22nd, 2005, 02:02 PM
#5
Re: How to open a Form??
Actually, the form is instanciated only once in your example so when it is .Closed it will no longer be able to be shown.
You should have it like this to allow the button click to show the form over and over and yet keep resources low.
VB Code:
Dim myForm As Form2
Private Sub Command1_Click()
If myForm Is Nothing Then
myForm = New Form2
End If
myForm.ShowDialog
End Sub
Private Sub Command2_Click()
myForm.Close ' or myForm.hide
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 22nd, 2005, 04:35 PM
#6
Thread Starter
Junior Member
Re: How to open a Form??
Thanks...
That helped me get started!!
Claus
-
Jun 22nd, 2005, 06:26 PM
#7
New Member
Re: How to open a Form??
Not wanting to jump in on someone else's thread, but this pertains to what I'm doing... I've got a TreeView which has 4 nested nodes, much like a Windows Explorer tree, except that it will never go more than 4 nodes deep.
Each subcatagory opens a different form (a dialog box) inside the main (parent) form. Only 1 of these forms will ever be seen at any given time. Should I instanciate all 4 forms and then just show the correct one and repopulate it, or should I dispose of each one when it is not needed?
In the On_Click event for the TreeView I have code like this:
Dim frmComp, frmDept, frmLoc, frmMachine, frmAssess As Form
frmComp = New frmCompany
frmComp.MdiParent = Me
frmDept = New frmDepartment
frmDept.MdiParent = Me
frmLoc = New frmLocation
frmLoc.MdiParent = Me
frmMachine = New DataForm2
frmMachine.MdiParent = Me
Then, I show the form like this:
If TreeView1.SelectedNode.Tag = "company" Then
frmComp.Show()
ElseIf TreeView1.SelectedNode.Tag = "department" Then
frmDept.Show()
ElseIf TreeView1.SelectedNode.Tag = "location" Then
frmLoc.Show()
ElseIf TreeView1.SelectedNode.Tag = "WE" Then
frmMachine.Show()
x = "WE"
End If
If x = "WE" Then
gstrPassedNode = TreeView1.SelectedNode.Tag
Else
gstrPassedNode = TreeView1.SelectedNode.Text
End If
Just wondering if I'm on the right track here. Thanks.
john
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
|