CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Form Loaded

  1. #1
    Join Date
    Jul 2000
    Posts
    124

    Form Loaded

    How can you test if a form is loaded?

    Thanks!
    Erica


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Form Loaded


    Public Function IsLoaded(ByVal form_name As String) As Boolean
    Dim frm As Form

    IsLoaded = False
    For Each frm In Forms
    If frm.Name = form_name Then
    IsLoaded = True
    Exit For
    End If
    Next frm
    End Function


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jul 2000
    Posts
    124

    Re: Form Loaded

    How do I bring a form window to the front? Is there a property that I can say frm.bringToFront? or something to that effect?

    Thanks!
    Erica


  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Form Loaded

    Use the ZORDER method ie:

    Form1.Zorder 0
    'or
    Form1.Zorder 1



    0 or Omitted says position form to the front. 1 says position it at the back.

    John G

  5. #5
    Join Date
    Jul 2000
    Posts
    124

    Re: Form Loaded

    I'm trying that and its not working. I have a whole bunch of forms in an MDI application. I have a menu and when I click on a form off the menu that's already loaded, it won't bring it to the front...

    Erica


  6. #6
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Form Loaded

    Use the ShowWindow API.

    Call ShowWindow(YourForm.hWnd,SW_SHOW)

    If you need more control, then there is the SetWindowPos() API function


  7. #7
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Form Loaded

    '
    ' Declarations
    '

    Public 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

    '----------------------------------------------
    ' Sets a form Topmost
    '

    Public Sub SetTopMost(ByVal lHwnd As Long, ByVal bTopMost As Boolean)
    '
    ' Set the hwnd of the window topmost or not topmost
    '
    Dim lUseVal As Long
    Dim lRet As Long

    lUseVal = IIf(bTopMost, HWND_TOPMOST, HWND_NOTOPMOST)

    lRet = SetWindowPos(lHwnd, lUseVal, 0, 0, 0, 0, SWPFLAGS)

    If lRet < 0 Then
    '
    ' Couldn't do operation - handle error here
    '
    ' DisplayWinAPIError lRet
    End If

    End Sub


    ==================
    ' To Set Form1 Top-Most

    SetTopMost Form1.hwnd, True

    ' To set it back

    SetTopMost Form1.hwnd, False


    '===========================================use API from the top
    '===One more way to set on top - On the form or module level
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2

    Private Sub OnTopCheck_Click()
    '------------------------------
    If OnTopCheck.Value = vbChecked Then
    SetWindowPos hwnd, HWND_TOPMOST,0,0,0,0, SWP_NOMOVE + SWP_NOSIZE
    Else
    SetWindowPos hwnd, HWND_NOTOPMOST,0,0,0,0, SWP_NOMOVE + SWP_NOSIZE
    End If
    End Sub



    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured