Obtaining sizing handles at runtime

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

mackaydAuthor Commented:
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.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mackaydAuthor Commented:
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!
mackaydAuthor Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.