|
-
Jul 14th, 2005, 11:18 AM
#1
Thread Starter
Fanatic Member
[SOLVED] showing form... (back in time, it was so easy!)
I remember back in time, when there was no .NET, naviguating through form was so easy... Now, with that .NET framework... it's big deal... I've been stuck for 3days on how to call a page... I search the msdn, this forums and google, and I just dont find something simply explaind.. I just want to call form2 from the menu on my form1. I dont want to create a new form, I want to show a form I already desinged... I know there is some declaration, but what is that initializing thing??? Anyone can provide some simple sample code... please, thank you all!!! realkly appreciated
Jean Christiophe Avard
Last edited by jcavard; Jul 14th, 2005 at 12:21 PM.
-
Jul 14th, 2005, 11:53 AM
#2
Lively Member
Re: showing form... (back in time, it was so easy!)
Inside your click event for the menu item -
Dim NewForm as New Form2
NewForm.Show()
(designing a form doesn't create an instance of it, it just outlines what it should be when created. the only reason the first form is created by default is because it is set as the startup object for the project you are working on)
-
Jul 14th, 2005, 11:54 AM
#3
Re: showing form... (back in time, it was so easy!)
VB Code:
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
' Detailed way
Dim frm As Form2
frm = New Form2
frm.ShowDialog()
'short way
Dim frm2 As Form2 = New Form2
frm.ShowDialog()
End Sub
You may also look to this thread
-
Jul 14th, 2005, 11:57 AM
#4
Re: showing form... (back in time, it was so easy!)
If your Form2 is already initialized in your project and you want to access it from Form1 then it depends on how you are starting
your project and what the startup object is.
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 
-
Jul 14th, 2005, 12:04 PM
#5
Re: showing form... (back in time, it was so easy!)
This way you can access any form object throughout your project without having to instanciate a new one, but then
more resources since all forms are instanciated all the time, etc.
Set your startup object to Sub Main, add a Module to your project.
VB Code:
Option Explicit On
Module Module1
Public goForm1 As Form1
Public goForm2 As Form2
Public Sub Main()
goForm1 = New Form1
goForm2 = New Form2
Application.Run(goForm1)
End Sub
End module
'Behind form1
Option Explicit On
Public Class Form1
'blah, blah...
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
goForm2.ShowDialog()
End Sub
End Class
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 
-
Jul 14th, 2005, 12:05 PM
#6
Re: showing form... (back in time, it was so easy!)
Hi,
I'm sure this has been said on this forum many times before, and will continue to be said again. I don't know if I can put it any simpler than that which has already been said, but I will try.
Dim newform2 as New Form2
YOU ONLY DO THIS ONCE, EITHER WHEN YOUR PROGRAM LOADS OR THE FIRST TIME YOU NEED THE FORM
newform2.show
YOU DO THIS EVERY TIME YOU WANT TO SHOW FORM 2.
I know you design the forms using the objects from the toolbar at design time. But when it comes to runtime, this form is a bit like a generic CommandButton or TextBox, or any other object. You don't just refer to "Commandbutton.text", you have to choose a Particular Commandbutton, e.g. "Commandbutton1.Text". Similarly, you don't actually have a Form2 until you load one up based on the template which you designed at design time, and you don't just have "Form2", you have a particular Instance of Form2, called "newform2".
Think of the forms at design time solely as templates rather than as objects, and it will become a bit easier to understand.
So, in your menu, you don't want to be creating a new version of Form2 from the template each time. Hence all you want is "newform2.show". However, this "newform2" has to be created at some point, using the line:
Dim newform2 As New Form2
You could do this in the Form1 class (right at the top of the code for Form1), or in a module, or in fact almost anywhere else.
"newform2" then behaves like anything else created at runtime - it is only valid as a reference within the area of code at which you created it. So if you made a button and put the "Dim newform2..." in there, your program would only recognise this name until the end of the "Command1_Click" event.
If you want to get it out of a particular section of code, you have to pass it out or declare it at a level at which other bits of your code can see it, such as in a module.
Does this make any sense? Quote bits that don't and I'm sure somebody will try to help.
There are so many posts coming up on this subject so regularly that it would be good to get one that everyone can understand and have it Stuck to the top for a while....
HTH
zaza
-
Jul 14th, 2005, 12:19 PM
#7
Thread Starter
Fanatic Member
Re: showing form... (back in time, it was so easy!)
thanks zaza, thank you everuyone soooo much!! that really helped me!
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
|