Library tutorials & articles

Forms

Introduction

Forms are the basis for all Windows applications. When you create a new project, VB automatically creates a form. You then add labels, text boxes and toolbars etc onto this. Think of it as a blank piece of paper on which to create your masterpiece. However, even as a piece of paper you need to make sure that it is the right size, and of the right quality. In the case of forms, you need to set a few properties, so it will look and behave how you want it to. This is covered in the next section.

Comments

  1. 02 Jul 2005 at 17:09

    In my program I have two forms. The user is asked to input a number in my custom-made form (input box) which has "OK", "CANCEL" and the input textbox.


    Basically the problem is if if the user presses "Cancel" in my custom input box, the sub in the first form will just continue being played out when I want to pretty much "cancel" it. How can I make the "cancel" button in my second form make the sub in the first form end?


    Thanks!

  2. 17 Feb 2005 at 14:37

    true, i noticed that my tray icon doesnt disappear automatically, cause the unload method of the form its on isnt loaded...


    ah well it works fine if you need to really kill it i guess

  3. 17 Feb 2005 at 13:38

    You don't really want to use End, as it forcefully terminates everything, rather than gracefully telling the forms that they're about to be closed (ie the Unload event), and then removing them from memory...

  4. 17 Feb 2005 at 13:19

    i know an even simpler method:


    Code:

    Public Sub CloseAll()
       End
    End Sub


    it works fine for me

  5. 31 May 2003 at 02:11

    If you replace "vbModeless" with "vbModal" then no window below can be clicked on!  Great for setting options.

  6. 27 Mar 2003 at 19:22

    okay, we'll welcome to the both of you.


    To show a form, you can do it in a few ways.


    If you want to show aform and stop the process from being able to execute any more comments until the form is close we would do this:


    frmForm.Show vbmodal


    what that means is say this scenario:

    Code:

    FormLoad()
    on error goto ErrH
    dim i as integer
    i = 1000
    i = i / 0
    errH:
    frmForm.Show vbmodal
    Resume Next
    end sub

    now that will cause a 'Divide by Zero' error when you run it because of the i=i/0 line. We are using Eroror handling(first line under the Form
    Load() statement) so it will goto the ErrH: area and execute what ever is underneath it. By running it in a Modal state we will stop the excution of commands until the form is dismissed by the user.


    Now what if you didnt want to show the form and stop executing? Simple use the .Show method on the form.


    Okay i hear you say "Okay smarty pants.. what if i want to float the form ontop of a form?(Eg. Form1 ontop of Form2?) huh? Huh? think you so smart try that one? come on comone? huh... wanna start me now? huh?"...


    we'll no need to get so jumpy... we simply do this: form1.show , form2 where Form2 is the parent form of form1!


    now when your unloading you forms its important to unallocate the memory that the form may be occupying. You can achieve this by this:


    Code:

    {rivate sub Form_Unload(cancel as integer)
    On error resume next '// Just incase
    set <form name> = nothing '// unallocatoin
    End sub


    As for loading and unloading as HyperHacker has said... you would use that if your intending to load a form prior to showing it, typical scenario is when you display a Splash screen, in the background all the forms are being loaded(yes theres a reason for the Splash screen and its not just for nice logos!)...


    Does this help?

  7. 27 Mar 2003 at 17:43

    Say your button is command1, then, if you mean what I think you mean:


    Private Sub command1.Click()
    form1.hide
    form2.show
    end sub


    Simple enough to understand. You can use .load and .unload rather than .show and .hide to make the program use less memory, but it'll be slower (and I'm having trouble getting .unload to work).
    [edit] Aha, here it is. To use the more RAM-friendly but slower load/unload, you would do this:
    unload form1
    load form2


    Strange how form1.load didn't cause an error, but .unload did. O_o

  8. 24 Feb 2003 at 03:41
    Im very new at VB, and I just need to know how to make a

    >>Button to Link to another Form<<

    Please Help!
  9. 09 Aug 2002 at 13:26

    I cannnot get the inner form width on a Mdi form expanded to more than normal screen resolution.

  10. 08 Mar 2002 at 15:21

    Check out the following code:

    Code:
    Public Sub CloseAll()


    Dim frmForm As Form
    On Error Resume Next
    'close all forms
    For Each frmForm In Forms
       Unload frmForm
    Next
    End


    End Sub

  11. 08 Mar 2002 at 14:55

    You use the

    Code:
    Unload theForm
    statement, as mentioned on


    http://www.developerfusion.com/show/72/5/

  12. 08 Mar 2002 at 14:16

    You mensioned that loaded forms take memory, but never mension how to close them all when your program ends. Probably the FIRST thing you need to learn if your application uses more then one form. Visual Basic does Not nessasarily release this memory otherwise, I know

  13. 01 Jan 1999 at 00:00

    This thread is for discussions of Forms.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback