Move and Resize Controls at Runtime Like the VB IDE.

Category:
Forms and Controls
Type:
Modules
Difficulty:
Advanced
Author:
Benoit Frigon

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
This module allow you to move and resize controls at run-time. All you have to do is register a container(e.g. Picture box) that contains your objects (Don't forget to unregister this container before the program ends!). The technique is simple. I subclass every objects and analyse their windows messages. When they receive the WM_NCHITTEST message, I return the HTTRANSPARENT code which tells windows that the input received must be passed to the window under (the container). Then I can analyse which objects is being selected and start the move/resize prodedure.

I added a snap-to-grid feature. It also displays the grid(Like VB IDE does). The only drawback is that it won't display picture box in the container background. Also, since the module requires windowed controls to work, it will not handle labels and shape control. However, you can still use them by putting them in a picturebox or you can use CreateWindowEx to create a static control (similar to labels).

Note: Code updated by author, 07/11/02.


Instructions: Click the link below to download the code. Select 'Save' from the IE popup dialog. Once downloaded, open the .zip file from your local drive using WinZip or a comparable program to view the contents.

Download ctrldragii.zip