Avatar of mmalwan
mmalwan
 asked on

resize a control at run time

Hi
I want to resize a control on a form at run time, is there any API or any idea?
thanks
MMAlwan
Visual Basic Classic

Avatar of undefined
Last Comment
mmalwan

8/22/2022 - Mon
Belfry

Yes, you can use windows API MoveWindow()

first you declare it as private or public,e.g:

Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

then use it in Form_Resize(), following is a sample

Private Sub Form_Resize()
'set scalemode to pixels so that it fits the API's scale mode
Me.ScaleMode = vbPixels

'center the command button
MoveWindow Command1.hwnd, Me.ScaleWidth / 2 - Command1.Width / 2, _
            Me.ScaleHeight / 2 - Command1.Height / 2, _
            Command1.Width, _
            Command1.Height, _
            True            
End Sub

Good Luck!
muskad202

u can do it without api also..

command1.top = ...
command1.left = ...
command1.width = ...
command1.height = ...

note that the values will be in twips..not pixels.
RMatzka

And still shorter:
Command1.Move l,t,w,h
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
xThorx

When you resize a form, an events form_resize() is called. You can then use the form dimension as refernce and modify the height, width (top, left) of your control in this event.
mmalwan

ASKER
hi
i don't mean that, what i mean is resizing a control like at disign mode (changing its width and height using the mouse)
MMAlwan
ASKER CERTIFIED SOLUTION
xThorx

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mmalwan

ASKER
thanks all
xThorx I want some thing like when u ar in vbasic IDE and u want to resize the project browser for exemple, so when u are on the edge of the control the mouse pointer became a double arrow and a thin line move if u press on the left button of ur mouse.

MMAlwan
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
xThorx

In the mouseup event, you have to change the pointer. To have a thine line, you have to draw it and to make it visible when you have the mouse down button and delete it when you have button 1 realesed.
mmalwan

ASKER
thanks all
u may have to add something like a thin picture box to be like in vb
MMAlwan