|
-
Jan 31st, 2004, 09:12 AM
#1
Thread Starter
Junior Member
Launching forms from forms (n00b)
I'm a newbie :P
I need to know the code to launch a form from a button.
Probably the simplest thing for you but i dont know 
Less importantly i need to know how to put a picture on and then when it is pressed launches a URL.
Adam
-
Jan 31st, 2004, 09:43 AM
#2
PowerPoster
Hi
Put this in the button Click event
Dim frm1 As New FormN
frm1.Show
Where FormN is the name of the form (more correctly form class) you want to show. This is called creating an Instance of the form
I found the MS.NET help files on Inheritance and on Classes very good. It is totally different from VB6.
Also have a look at threads
http://www.vbforums.com/showthread.p...hreadid=277102
http://www.vbforums.com/showthread.p...hreadid=277026
for associated helpful comments.
Best of luck.
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.
-
Jan 31st, 2004, 12:38 PM
#3
Frenzied Member
I alluded to this in a previous post, but there's also scope issues. If you declare the form in an event, function, or procedure, it's life is limited to the life of the e/f/p that created it. So if you declare the form in a click event, for example, the form will cease to exist after the event is done.
If this isn't what you want, declare the form as a form or global variable. You can leave out the New keyword in the declaration if you later set it in a statement.
I ran into that problem the other day. Another option is to call the form with ShowDialog instead of Show, if that's appropriate for you.
-
Jan 31st, 2004, 12:47 PM
#4
Thread Starter
Junior Member
Thankyou. The information has helped a lot
-
Jan 31st, 2004, 01:14 PM
#5
PowerPoster
Hi salvelinus
"Another option is to call the form with ShowDialog instead of Show, if that's appropriate for you."
Just for my education, why use ShowDialog here? I thought that, e.g. frmOne. ShowDialog was intended for use where you did not want the user to be able to access any other form until frmOne had been closed (Except other forms opened from frmOne).
Adam, make sure you check out the threads I mentioned as there is a lot more quite important aspects on opening forms than we are covering here.
Regards,
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.
-
Jan 31st, 2004, 01:31 PM
#6
Frenzied Member
Originally posted by taxes
Hi salvelinus
"Another option is to call the form with ShowDialog instead of Show, if that's appropriate for you."
Just for my education, why use ShowDialog here? I thought that, e.g. frmOne. ShowDialog was intended for use where you did not want the user to be able to access any other form until frmOne had been closed (Except other forms opened from frmOne).
Yes, that's true. It may not be appropriate. But say frmOne was a password form, or a required entry form of some sort. Then you'd want it as a dialog box.
I'm fairly new to .Net myself, but I think if you opened other forms from an e/f/p in frmOne, which itself had been opened in an e/f/p in another form, those forms would go out of scope once the e/f/p in frmOne was done. Assuming they're declared in the e/f/p, anyway.
The gurus on the board will probably have a better way, though.
-
Jan 31st, 2004, 06:05 PM
#7
yay gay
Originally posted by salvelinus
I alluded to this in a previous post, but there's also scope issues. If you declare the form in an event, function, or procedure, it's life is limited to the life of the e/f/p that created it. So if you declare the form in a click event, for example, the form will cease to exist after the event is done.
If this isn't what you want, declare the form as a form or global variable. You can leave out the New keyword in the declaration if you later set it in a statement.
I ran into that problem the other day. Another option is to call the form with ShowDialog instead of Show, if that's appropriate for you.
Sorry but i dont believe that's true, in c++ it might be but in .NET even after the button event has passed the form is still alive
\m/  \m/
-
Jan 31st, 2004, 06:12 PM
#8
Frenzied Member
I stand partially corrected, at least. Sub Main, when using Application.Run, would usually always be in scope.
But I still think (w/o a test environment here) that declaring a form in an e/f/p would limit it's scope to the life of the e/f/p.
Maybe vb.net works differently, but that would violate scope rules.
-
Jan 31st, 2004, 09:11 PM
#9
PowerPoster
Hi PT Exorcist,
Yes, that checks out. Even if the calling form is closed (unless that calling form is the start form of the application) the called form IS still alive and you can click on any of it's objects, but it seems you cannot access it or it's methods, even if declared Public Shared from any other form. Is that correct?
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 1st, 2004, 01:01 AM
#10
Originally posted by salvelinus
I stand partially corrected, at least. Sub Main, when using Application.Run, would usually always be in scope.
But I still think (w/o a test environment here) that declaring a form in an e/f/p would limit it's scope to the life of the e/f/p.
Maybe vb.net works differently, but that would violate scope rules.
That is the Garbage Collector's fault. It only removes things when they're not being used. SO, technically, VB.NET does abide by the basic rules of scope, but GC just breaks the hell out of them.
-
Feb 1st, 2004, 10:37 AM
#11
I wonder how many charact
The form lives on in memory until the GC collects it. But although the form is still existent in memory, it is marked for destruction, so it will be erased when the system determines it needs more memory.
Now, there a bunch of caveats to that, depending on how you launch the form, and who you make its owner, or if you launch it as a top level container or MDI child. As someone suggested, you best read up as much as possible.
-
Feb 2nd, 2004, 02:55 AM
#12
yay gay
Originally posted by nemaroller
The form lives on in memory until the GC collects it. But although the form is still existent in memory, it is marked for destruction, so it will be erased when the system determines it needs more memory.
Are you sure about this? I believe that if the form is still being used the GC will never delete it, and only when you stop using the form the GC may delete it from memory.
\m/  \m/
-
Feb 3rd, 2004, 08:25 PM
#13
I wonder how many charact
Well, you may be correct. There are about 4 different ways to scope a form... owner, mdi, etc... and I'm just far too lazy and indifferent to care to check.
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
|