Hello
How do I make a form stick to the postion of a picture box on another form? :confused:
Thanks
SgtSlayer
Printable View
Hello
How do I make a form stick to the postion of a picture box on another form? :confused:
Thanks
SgtSlayer
Responses I need Responses!
:wave: :wave: :wave: :wave:
Thanks
SgtSlayer
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
Thanks for the reply! Can you please post some example code I'am a noob
especially with API. :o
Thanks
SgtSlayer
1) Please don't bump threads after only 15 minutes ;)
2) Is it a window in your application or in an external program?
1) Ok Sorry
2) window in my application
Thanks
SgtSlayer
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: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.VB Code:
HookForm Me, frmSticky
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 :)
Great! :thumb:
But how do I do this?
ThanksQuote:
to the postion of a picture box on
SgtSlayer
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).
THANKS!!!
:thumb: :thumb: :thumb:
Thanks
SgtSlayer