Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Obtaining sizing handles at runtime

Posted on 1998-05-25
Medium Priority
Last Modified: 2008-02-26
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.
Question by:mackayd
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1

Expert Comment

ID: 1461580
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


Author Comment

ID: 1461581
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.

Expert Comment

ID: 1461582
When the click event occurs call the resize event and save the width and height to a global varaible and use it.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1461583
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.

Expert Comment

ID: 1461584
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!

Author Comment

ID: 1461585
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.


Expert Comment

ID: 1461586
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.

Accepted Solution

bin_huwairib earned 400 total points
ID: 1461587

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

Expert Comment

ID: 1461588

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.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question