?
Solved

resize a control at run time

Posted on 2003-02-26
9
Medium Priority
?
161 Views
Last Modified: 2010-05-01
Hi
I want to resize a control on a form at run time, is there any API or any idea?
thanks
MMAlwan
0
Comment
Question by:mmalwan
[X]
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
9 Comments
 
LVL 1

Expert Comment

by:Belfry
ID: 8023688
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!
0
 
LVL 2

Expert Comment

by:muskad202
ID: 8023813
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.
0
 

Expert Comment

by:RMatzka
ID: 8024197
And still shorter:
Command1.Move l,t,w,h
0
Technology Partners: 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!

 
LVL 1

Expert Comment

by:xThorx
ID: 8024779
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.
0
 

Author Comment

by:mmalwan
ID: 8024821
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
0
 
LVL 1

Accepted Solution

by:
xThorx earned 160 total points
ID: 8025021
You have then to play with the mousedown event of the form and if the cursor is between the edge of the control and X, you can then resize the control if the button 1 of the mouse is activated.

Try this: all you need is a textbox named text1 on a form.

Dim NEWX, NEWY As Long

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 And (X > Text1.Left + Text1.Width And X < Text1.Left + Text1.Width + 100 Or _
        Y > Text1.Top + Text1.Height And Y < Text1.Top + Text1.Height + 100) Then
        NEWX = X
        NEWY = Y
    End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If NEWX <> 0 Or NEWY <> 0 Then
        With Text1
            .Height = Y - .Top
            .Width = X - .Left
        End With
        NEWX = 0
        NEWY = 0
    End If
End Sub
0
 

Author Comment

by:mmalwan
ID: 8055757
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
0
 
LVL 1

Expert Comment

by:xThorx
ID: 8056039
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.
0
 

Author Comment

by:mmalwan
ID: 8093541
thanks all
u may have to add something like a thin picture box to be like in vb
MMAlwan
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

770 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