Results 1 to 8 of 8

Thread: [RESOLVED] Form Always on top

  1. #1

    Thread Starter
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Resolved [RESOLVED] Form Always on top

    how do make my form always on top of other form in my application without using modal
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Form Always on top

    There is a way to do it Here
    (I'm not sure if thats the best way)

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Form Always on top

    To keep a program window on top (always visible) in Visual Basic use a WINAPI function. Code in Main Module:

    Code:
    Declare Sub SetWindowPos Lib "User" (Byval hWnd as integer, Byval hWndInsertAfter as Integer, Byval X as Integer, Byval Y as Integer, Byval cx as Integer, Byval cy as Integer, Byval wFlags as Integer)
    Code in a Submodule:
    Code:
    SetWindowPos form1.hWnd, -1, 0, 0, 0, 0, &H50 'This will make the window always visible!
    
    SetWindowPos form1.hWnd, -2, 0, 0, 0, 0, &H50 'This will put "Always Visible" off!

    just give a try...coz I never used this
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Form Always on top

    its not working,

    what i actually want is that my form will be placed on top of every form in my application without being on top of ther applications.
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Form Always on top

    Try this
    Code:
    Form2.Show vbModeless, Me

  6. #6
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: Form Always on top

    Module:

    Code:
    Option Explicit 
    
    Public Const HWND_TOPMOST = -1 
    Public Const SWP_NOMOVE = &H2 
    Public Const SWP_NOSIZE = &H1 
    
    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
    Form
    Code:
    Private Sub Command1_Click()  ' activate
        SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _ 
        SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE 
    End Sub 
    
    Private Sub Command2_Click()  ' deactivate
        SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _ 
        SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE 
    End Sub


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  7. #7
    Addicted Member
    Join Date
    Feb 2006
    Location
    The Sea of Tranquility
    Posts
    252

    Re: Form Always on top

    if GetTopWindow(0) <> form1.hwnd then

    'setwindowpos

    end if

    Rich

  8. #8

    Thread Starter
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Form Always on top

    thanx for the help guys
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

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