Cool Visual Basic
 
Main
Frequently Asked Questions
VB Helpdesk
Message Boards
Library
Downloads
View Guestbook
Add to Guestbook
Product Reviews
Bookstore
Links
Newsgroups
Vendors
Affiliates
Cooltech.org

Cool VB FAQ


Text Format

The best Visual Basic FAQ(Frequently Asked Quesitions) file on the internet. Do you have a problem that's got you stumped? Do you have the answer to one? We've done our best to make this the best resources for the questions and the answers. Post a question, or a answer to one, by sending email to VBQA@beadsandbaubles.com.

      Root

            Forms

  • How can I create a window with a small title bar?

    Compatibility:VB3  VB4  VB5

    Just set the WindowStyle property to "Sizable Toolwindow" or "Fixed Toolwindow".

     

     

  • What's the difference between Modal and Modaless forms?

    Compatibility:VB3  VB4  VB5

    When a modal form is active, no otherforms in your program can get the focus.

    To display a modal form, use the following code:

    myForm.show 1
    

     

     

  • How can I create a window with no title bar?

    Compatibility:VB3  VB4  VB5

    You have to set the following properties on your form: Title = blank MinBox = False MaxBox = False ControlBox = False

     

     

  • How can I put a toolbar in my application?

    Compatibility:VB3  VB4  VB5

    Create a new form with all your buttons on it. Under VB5, you'll want to set the border property to "4 - ToolWindow".

    Put the following declarations in a new module:

    declare Function SetWindowWord Lib "User32" (ByVal hWnd as Long, ByVal _
     nIndex as long,  ByVal nNewWord as long) as long
    

    Next, put the following code in the load event of the toolbar form.

    SetWindowWord Me.hWnd, -8, Main.hWnd
    

    Replace main with the name of your main form.

     

     

  • I've heard that using END is dangerous; what's the best way to end my program?

    Compatibility:VB3  VB4  VB5

    To end your program, use this code:

    	dim ret as object
    
    	for each ret in forms
    		unload ret
    		set ret = nothing
    	next
    

     

     

  • What's the difference between hiding a form and unloading it?

    Compatibility:VB3  VB4  VB5

    When you unload a form, you're taking the graphical portion of the form out of memory. When you hide a form, you're just telling Windows to stop displaying that form. Hiding a form is faster; Unloading a form takes up less memory.

    In order to unload the code portion of a form, use the following code:

          set MyForm = nothing
    

     

     

  • How can I center a form onto the screen?

    Compatibility:VB3  VB4  VB5

    Simple. In VB5, just set the StartUpPosition property of your form to your desired setting.

    In VB4/VB3, do this:

    sub CenterForm(myForm as object)
           myform.left = (screen.width / 2) - (myform.width / 2)
           myform.top = (screen.height / 2) - (myform.height / 2)
    end sub
    

     

     

  • How can I make a form "Always on top"?

    Compatibility:VB3  VB4  VB5

    Put this code in a module:

    Declare Function SetWindowPos Lib "user32" ( _
        ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
        ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
        ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOMOVE = &H2
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    
    public sub SetFormOnTop(myForm as object)
            SetWindowPos myForm.hWnd,  HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
    end sub
    

     

     

  • How can I minimize all the forms in my project at once?

    Compatibility:VB3  VB4  VB5

    Copy this code into a module:

    sub MinimizeAllForms()
          dim objTemp as object
    
          for each objTemp in forms
               objTemp.windowstate = 1
          next
    end sub
    

     

     

  • How can I tile a image on a form?

    Compatibility:VB3  VB4  VB5

    Put the following code in your form_paint:

    dim i as integer, j as integer
    
    for i = 0 to scalewidth step picture1.width
       for j = 0 to scaleheight step picture1.height
            paintpicture picture1.picture, i, j
       next
    next
    

    and replace picture1 with the name of your picturebox or imagebox control.

     

     

    LinkExchange
    LinkExchange Member Free Home Pages at GeoCities


    Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.