|
-
Feb 6th, 2004, 06:05 PM
#1
Thread Starter
Frenzied Member
Changing Forms, the .NET Way?
In VB6 I used to have a Main menu and all my forms came off that, to change the forms I used
Now, how do I do this in .NET?
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Feb 6th, 2004, 07:20 PM
#2
PowerPoster
Hi,
You first create an instance of the form to be opened then you make it visible, for example
Dim frmCurrent as New frmOne
frmCurrent.Show
If you use the samename for the current form, assuming you have only one subsidiary form open at a time, it makes the coding for showing the various subsidiary forms simpler.
When you have finished with it you would normally put the following in the click event of an Exit button on that form:
Me.Close()
or (less likely) put the following in the click event of a button on the main form:
frmCurrent.Close
Although the words look very similar to VB6, they are accomplishing a very different chain of events. Have a look at articles on Inheritance in the MSDN help files and search the subject in this forum.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 6th, 2004, 08:46 PM
#3
Thread Starter
Frenzied Member
OK, i tried that, when i execute the code on the main form, it closes the program. Is this common in all .NET or a VB.NET 2002 issue?
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Feb 7th, 2004, 03:51 AM
#4
Hi.
You can not close your main startup form.
If you do, you close the whole app.
If you need to, you can hide the main form, while showing the second form.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Feb 7th, 2004, 04:07 AM
#5
PowerPoster
Hi,
Totally different problem. As I said, you are going to have to forget your VB6 knowledge when it comes to forms (and all other objects). You MUST become familiar with Inheritance, otherwise you will continue to ask very basic questions on this forum.
You are probably trying to open the form in the VB6 manner than creating an instance in the VB.NET manner. Although you CAN do this the VB6 way, you will run into all sorts of problems, including the one you mention.
Always use a module to start your programme.
When you design a form named, for example, frmMain, you actually design a class (or more correctly a Sub Class) of that name, which is why you are (or should be) taught to name it fclsMain. The form does not actually exist in your running programme. What you have to do is to create an Instance of fclsMain by a declaration. So, in the General Section of the Module write;
Dim frmFirst as New fclsMain or
Public frmFirst as New fclsMain
Then, in the same Module create your Sub Main:
Private Sub Main()
Application.Run(frmFirst)
End Sub
frmFirst will be an EXACT copy of fclsMain.
Make Sub Main the startup object of your project and away you go.
PS. I have just re-read your last post and there may be a slight misunderstanding. In my first reply, I understood you to say that you wanted to have a main form and then run all your other forms from it (your terminology). Therefore in the above example, you would, for example, have the following code in a button click event on fclsMain assuming you have designed a form named fclsStatement:
Dim frmCurrent as New fclsStatement
frmCurrent.show()
The closing of that form can be achieved either by putting the following in the click event of a button in fclsStatement:
Me.Close()
or putting the following in the required event in fclsMain:
frmCurrent.Close()
If at any stage you close frmFirst without closing frmCurrent, you will terminate the project ( you can take steps to avoid that if required).
Best of luck.
Last edited by taxes; Feb 7th, 2004 at 04:26 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 7th, 2004, 06:22 AM
#6
Thread Starter
Frenzied Member
Originally posted by pax
Hi.
You can not close your main startup form.
If you do, you close the whole app.
If you need to, you can hide the main form, while showing the second form.
I tried that, but when i said Main.show etc it loaded a new instance of it for some unknown reason.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Feb 7th, 2004, 06:30 AM
#7
Thread Starter
Frenzied Member
Taxes, thanks for taking the time to reply, i will certinly look into what you said. Looks like you got the idea.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Feb 7th, 2004, 12:52 PM
#8
New Member
You can also simply hide the first form with "me.hide". You have to remember it's just hidden, though, if you plan to return data to it later (i.e. don't launch another instance of the form).
-
Feb 7th, 2004, 01:41 PM
#9
PowerPoster
Hi Ideas Man,
"If you need to, you can hide the main form, while showing the second form.
--------------------------------------------------------------------------------
I tried that, but when i said Main.show etc it loaded a new instance of it for some unknown reason."
That should not happen. How do you know it is another instance? I have just checked it out and it works O.K. When you used MainForm.Show, did you use any other code as well? Did you declare it again?
Regards,
Last edited by taxes; Feb 7th, 2004 at 03:46 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 7th, 2004, 06:12 PM
#10
Thread Starter
Frenzied Member
I know it loaded another instance because i put a textbox on the form, and hid it, then opened another form, closed it and showed the main one again and the text in the textbox was back to the default. I'll look at the code again though to see wha went wrong.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
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
|