Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

resize a control at run time

Posted on 2003-02-26
9
Medium Priority
?
164 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
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
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!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

571 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