Obtaining sizing handles at runtime

mackayd used Ask the Experts™
I have a number of picturebox controls that I would like to allow the user to resize while my applicaiton is running, much in the way I can during the development phase with the rectangles in each corner and along each edge.

I know that this can be done fairly easily with the CRectTracker control in Visual C++/MFC but I have a lot of code already in VB and don't want to start mixing and matching.

The basic question is - how can I bring up the resizing rectangles around a control at runtime and then get the feedback (events) as the user adjusts the size and location of the control.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
resize event :-
applies to picture control and accours when the size of the object changes.
The resize event has three parts
object-controlname -which is ur picturebox
height = number specifying the new height of the control
width   =number specifying the new width of the control


The resize event occurs *AFTER* the item has moved or changed size. I want to be able to 'click' on the item and have the resizing handles appear so I can them "grab" one of them to resize the control.

I want to emulate the way I can locate and resize a control in the development environment but while my applicaiton is running.
When the click event occurs call the resize event and save the width and height to a global varaible and use it.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


I'm sorry but I think you have missed the point. I don't see that the Resize event comes into this as such.

I have a picturebox control with a normal line as a border. I want to add a small rectangle in each corner and one half way along each side and have the cursor set for each rectangle so that it indicates which direction the user can move. Dragging the rectangle will then (possibly) trigger the resize event so that the underlying picturebox can adjust to the new size. (If you think this sounds like a 'standard' thing in the development environments - it is!)

This sort of thing happens all of the time with all controls in the development environment. It just seems to me that I could be spending a lot of time writing the code to do this when it has already been done.

Dan Appleman has an amazing article on how to do just this.  In fact, it works for any control.  The article is quite long (it is actually divided into two parts), but it is exactly what you are looking for.

The article is contained on the CD for his book "The Visual Basic 5.0 Programmers Guide to the Win32 API".  The article is also on the MSDN CD

I am looking for a site that has a copy of the article posted.  As soon as I find a link, I will post it here.

Hope this helps!


Sorry about having to 'reject' your answer because it sounds like exactly what I want. However I don't have an option says "tell me more...".

I have searched the April 1998 MSDN library CD and can't locate the article you mention. (Lots of references to Dan/Daniel Appleman and the title of his book etc. but none that relate to this).

Could you please supply the title or more explicit information on the name of the CD (in case I got that wrong).

Once I've found the reference I'll be only too glad to accept the answer.


The article used to be on the MSDN but has since been removed to make room for newer material.  The article is still available on the CD that comes with Appleman's book (which you will need to understand all of the API calls).

Since you have already subscribed to the MSDN and, under normal circumstances, would still be entitled to the article, I will e-mail a copy of it to you.

Post your address and I will send it to you.


p.s. This is for Mackayd only.  I will not be able to respond to other requests for the article.

Try the following code it will solve your problem in other way, after you run the code click on any picture and here you go you can resize it as you like.

1- Add form1 to project1.
2- Add picture1, picture2 and picture3 to form1.
3- Paste this code:

Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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

Dim PrevControl As Control

Private Sub SetBorder(MyControl As Control, Yes As Boolean)
 Dim Style As Long
 Dim r As Long
 Style = GetWindowLong(MyControl.hwnd, GWL_STYLE)
 Style = IIf(Yes, Style Or WS_THICKFRAME, Style Xor WS_THICKFRAME)
 If Style Then
  r = SetWindowLong(MyControl.hwnd, GWL_STYLE, Style)
  r = SetWindowPos(MyControl.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
 End If
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If Not PrevControl Is Nothing Then SetBorder PrevControl, False
 SetBorder Picture1, True
 Set PrevControl = Picture1
End Sub

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If Not PrevControl Is Nothing Then SetBorder PrevControl, False
 SetBorder Picture2, True
 Set PrevControl = Picture2
End Sub

Private Sub Picture3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If Not PrevControl Is Nothing Then SetBorder PrevControl, False
 SetBorder Picture3, True
 Set PrevControl = Picture3
End Sub

Best regards
Bin Huwairib


An interesting solution but I do not think it is what mackayd is looking for.

I received your e-mail but, since you did not refer to the question within the e-mail, I did not relize it was you until now.  I will locate the artice and send it to you.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial