Results 1 to 10 of 10

Thread: [RESOLVED] Sticky Form

  1. #1

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Resolved [RESOLVED] Sticky Form

    Hello

    How do I make a form stick to the postion of a picture box on another form?

    Thanks
    SgtSlayer

  2. #2

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Re: Sticky Form

    Responses I need Responses!



    Thanks
    SgtSlayer

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Sticky Form

    GetWindowRect API function might be usefull. Use it in combination with a timer to make your window stick even if the other form is moved.

    http://msdn.microsoft.com/library/en...windowrect.asp

  4. #4

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Re: Sticky Form

    Thanks for the reply! Can you please post some example code I'am a noob
    especially with API.

    Thanks
    SgtSlayer

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Sticky Form

    1) Please don't bump threads after only 15 minutes

    2) Is it a window in your application or in an external program?

  6. #6

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Re: Sticky Form

    1) Ok Sorry

    2) window in my application

    Thanks
    SgtSlayer

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Sticky Form

    Baya_ju suggested that you would use GetWindowRect, which you should, and a Timer, which you shouldn't. GetWindowRect will provide you with the coordinates of the Form but using a Timer and constantly check these coordinates is just a waste of CPU. A better approach would be to subclass your Form and check for messages which (unfortunatly) VB doesn't provide as events. Such as when your Form is being moved and of course resized, this event is provided by VB but to keep it clean I've added that message as well to the project that I attached.

    A little warning though. Since you say you're new to APIs I'm guessing you're even newer to subclassing. When you use this approach you can NOT use the End keyword in your project to end the application (which you shouldn't do anyway) and you can't use the End button or menu item from inside VB (since that will just call the End function). Close your windows (from code) using the Unload statement and close and end the application by closing the Forms using the X button.

    The attached project shows how to hook one window next to another. Even if you don't understand the code you can easily do this in your own project by adding the StickyHook.bas module to your project. You would then just call the HookForm procedure from your Form_Load event (or at any other place) passing the parent window and the child (the sticky window) as parameters:
    VB Code:
    1. HookForm Me, frmSticky
    The form called frmSticky in the above call will then "stick" to the right edge of the parent form (Me) as long as it's loaded.

    You should also call the UnhookForm in the Form_Unload event of the "parent" form, but in case you forget to do that the module will take care of that as well.

    Just download the attachment and have fun with it
    Attached Files Attached Files

  8. #8

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Re: Sticky Form

    Great!
    But how do I do this?
    to the postion of a picture box on
    Thanks
    SgtSlayer

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Sticky Form

    Sorry, missed that part. The following attached example will do that. I've added a third argument to the HookForm sub which accepts the PictureBox. This PictureBox must however reside on the parent form (and the code actually doesn't check if that is the case so just make sure it is).
    Attached Files Attached Files

  10. #10

    Thread Starter
    Member SgtSlayer's Avatar
    Join Date
    Aug 2005
    Posts
    46

    Re: Sticky Form

    THANKS!!!


    Thanks
    SgtSlayer

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