Solved

Obtaining sizing handles at runtime

Posted on 1998-05-25
9
297 Views
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.
0
Comment
Question by:mackayd
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 1

Expert Comment

by:lekshmikr
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

0
 

Author Comment

by:mackayd
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.
0
 
LVL 1

Expert Comment

by:lekshmikr
ID: 1461582
When the click event occurs call the resize event and save the width and height to a global varaible and use it.
0
 

Author Comment

by:mackayd
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.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 4

Expert Comment

by:zsi
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!
zsi
0
 

Author Comment

by:mackayd
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.

Thanks
0
 
LVL 4

Expert Comment

by:zsi
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.

zsi

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

Accepted Solution

by:
bin_huwairib earned 200 total points
ID: 1461587
mackayd,

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_DRAWFRAME = &H20
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Const SWP_FLAGS = SWP_NOZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME
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
0
 
LVL 4

Expert Comment

by:zsi
ID: 1461588
Bin,

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

mackayd,
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.

zsi
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now