Consulting

Results 1 to 4 of 4

Thread: Drag the Excel userform

  1. #1

    Drag the Excel userform

    Hi, I'm new to VAB. Can anyone tell me how to drag the userform into smaller size instead of add in a toggle button to minimize it? Thanks in advance.
    Last edited by ahler; 03-21-2009 at 08:07 PM.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    At design time, the size of the UF is controled by the Width and Height properties in the Properties Window. The handle on the VB Editor is the editor's window only. I know of no way to freehand adjust the size of the UF at design time.

    If you want the user to be able to resize a userform at run time, a Label can give the user a control in the lower right corner to grab and resize the userform.

    Code changing the size and location of other controls will need to be added.

    [VBA]Dim xOffset As Single
    Dim yOffset As Single

    Private Sub Label1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    Rem me.width = (lable1.left + x) + xOffset
    Rem thus, xOffset = me.width - (label1.left + x)
    If Button = 1 Then
    If x > 0 Then xOffset = Me.Width - (Label1.Left + x)
    If y > 0 Then yOffset = Me.Height - (Label1.Top + y)
    End If
    End Sub

    Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    If (xOffset * yOffset <> 0) And (Button = 1) Then
    Me.Width = (Label1.Left + x) + xOffset
    Label1.Left = Me.Width - Label1.Width
    Me.Height = (Label1.Top + y) + yOffset
    Label1.Top = Me.Height - 22 - Label1.Height
    End If
    End Sub

    Private Sub Label1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)
    xOffset = 0
    yOffset = 0
    End Sub

    Private Sub UserForm_Initialize()
    With Label1
    .Width = 20
    .Left = Me.Width - .Width
    .Height = 20
    .Top = Me.Height - 22 - .Height: Rem 22 is height of caption bar
    End With
    End Sub[/VBA]
    PLEASE TRY THE ROUTINE BEFORE READING THE FOLLOWING:


    there is a quirk, the first time the user clicks on the label, nothing happens, its initializing,
    i wonder if an unwarned user will notice it.

  3. #3
    Mac Moderator VBAX Expert shades's Avatar
    Joined
    May 2004
    Location
    Kansas City, USA
    Posts
    638
    Location
    Howdy. Is this specific to the Mac?

    Software: LibreOffice 3.3 on Mac OS X 10.6.5
    (retired Excel 2003 user, 3.28.2008 )
    Humanware: Older than dirt
    --------------------
    old, slow, and confused
    but at least I'm inconsistent!

    Rich

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    Untested, but I think it would work on a Windows machine.

    The "trick" would be to define every control's position relative to the userform's width and height.
    Note that the code in the MouseMove event setting the .Left and .Top of Label1 is the same as the code in the Initialize event.

    With more controls than just the label, a sub PlaceAllControls would be useful, to be called in the Initialize event and in the MouseMove.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •