Results 1 to 13 of 13

Thread: Launching forms from forms (n00b)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2004
    Posts
    22

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2004
    Posts
    22
    Thankyou. The information has helped a lot

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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/

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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.

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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.

  12. #12
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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/

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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
  •  



Click Here to Expand Forum to Full Width