I have the following script which makes it so that you can resize a userform by dragging the bottom right corner.
Can anyone please provide a script so that I can resize it from
1 - The top right corner
2 - The bottom left corner
3 - The top left corner.
Sometimes I have textboxes in certain positions and want to resize to fit a specific textbox which this does not allow and will include every textbox above the textbox that I want.
Can anyone please provide a script so that I can resize it from
1 - The top right corner
2 - The bottom left corner
3 - The top left corner.
Sometimes I have textboxes in certain positions and want to resize to fit a specific textbox which this does not allow and will include every textbox above the textbox that I want.
Code:
Dim myClipbd As New DataObject
Private m_sngX As Single
Private m_sngY As Single
Option Explicit
Private Const MResizer = "ResizeGrab"
Private WithEvents m_objResizer As MSForms.Label
Private m_sngLeftResizePos As Single
Private m_sngTopResizePos As Single
Private m_blnResizing As Single
Private Sub UserForm_Activate()
'RemoveCaption GetForegroundWindow
'Call formheight
Set m_objResizer = Me.Controls.Add("Forms.label.1", MResizer, True)
With m_objResizer
With .Font
.Name = "Marlett"
.Charset = 2
.Size = 14
.Bold = True
End With
.BackStyle = fmBackStyleTransparent
.AutoSize = True
.BorderStyle = fmBorderStyleNone
.Caption = "o"
.MousePointer = fmMousePointerSizeNWSE
.ForeColor = RGB(100, 100, 100)
.ZOrder
.Top = Me.InsideHeight - .Height
.Left = Me.InsideWidth - .Width
End With
End Sub
Private Sub m_AddResizer()
'
' add resizing control to bottom righthand corner of userform
'
End Sub
Private Sub m_objResizer_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
m_sngLeftResizePos = X
m_sngTopResizePos = Y
m_blnResizing = True
End If
'If Button = 1 Then
'End If
'If Button And 1 Then
'End If
End Sub
Private Sub m_objResizer_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
With m_objResizer
.Move .Left + X - m_sngLeftResizePos, .Top + Y - m_sngTopResizePos
Me.Width = Me.Width + X - m_sngLeftResizePos
Me.Height = Me.Height + Y - m_sngTopResizePos
.Left = Me.InsideWidth - .Width
.Top = Me.InsideHeight - .Height
End With
End If
End Sub
Private Sub m_objResizer_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
m_blnResizing = False
End If
End Sub
Private Sub UserForm_Initialize()
' m_AddResizer
End Sub
Private Sub UserForm_Terminate()
Me.Controls.Remove MResizer
End Sub
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
m_sngX = X
m_sngY = Y
End If
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
Me.Left = X + Me.Left - m_sngX
Me.Top = Y + Me.Top - m_sngY
End If
End Sub