Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitlePosition a popup form below a TextBox
DescriptionThis example shows how to position a popup form below a TextBox in Visual Basic 6.
Keywordspopup, position, ClientToScreen, ShowWindow, SetWindowPos
CategoriesAPI, Controls, Software Engineering
 
When the program's main form loads, the code uses the SetWindowPos API function to make the popup form a topmost window.
 
' Make the popup form topmost.
Private Sub Form_Load()
    SetWindowPos frmPopup.hwnd, _
        HWND_TOPMOST, 0, 0, 0, 0, _
        SWP_NOMOVE + SWP_NOSIZE
End Sub
 
When you click the Show Popup button, the program uses the ClientToScreen API function to find the TextBox's position in screen coordinates. It moves the popup form there and uses the ShowWindow API function to display the form without giving it the focus.
 
Private Sub cmdShowPopup_Click()
Dim pt As POINTAPI

    pt.X = 0
    pt.Y = ScaleY(Text1.Height, ScaleMode, vbPixels)
    ClientToScreen Text1.hwnd, pt

    frmPopup.Move _
        ScaleX(pt.X, vbPixels, vbTwips), _
        ScaleX(pt.Y, vbPixels, vbTwips)
    ShowWindow frmPopup.hwnd, SW_SHOWNOACTIVATE
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated