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 :D
Less importantly i need to know how to put a picture on and then when it is pressed launches a URL.
Adam
Printable View
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 :D
Less importantly i need to know how to put a picture on and then when it is pressed launches a URL.
Adam
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.
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.
Thankyou. The information has helped a lot;)
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,
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.Quote:
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).
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.
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 aliveQuote:
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.
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.
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?
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.Quote:
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.
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.
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.Quote:
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.
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. :)