jimmy2timez
New Member
- Joined
- Apr 21, 2010
- Messages
- 48
Is there a "simple" code that allows a userform to be resized after it is open?
Strange ! that shouldn't happen because the project has a reference to the IAccessibility library by default .
Anyway, try this ;
Code:Declare PtrSafe Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc [B][COLOR=#ff0000]As Any[/COLOR][/B] , phwnd As LongPtr) As Long
Now the form is clearly resizable!
Option Explicit
Private lCustomZoom As Long
Public Property Get CustomZoom() As Long
CustomZoom = IIf(lCustomZoom = 0, Me.Zoom, lCustomZoom)
End Property
Public Property Let CustomZoom(ByVal ZoomFactor As Long)
If ZoomFactor <> Me.Zoom Then
Me.Zoom = ZoomFactor
Me.Width = Me.Width * ZoomFactor / 100
Me.Height = Me.Height * ZoomFactor / 100
End If
lCustomZoom = ZoomFactor
End Property
Private Sub CommandButton1_Click()
Me.CustomZoom = 80
End Sub
If Not boolSmall Then
'Me.Zoom = 80: Me.width = initWidth * 80 / 100: Me.height = initHeight * 80 / 100
Me.CustomZoom = 80
boolSmall = True
Else
'Me.Zoom = 100: Me.width = initWidth: Me.height = initHeight
Me.CustomZoom = 100
boolSmall = False
End If
the form height and width do not respect the ratio. They are a little smaller and if I repeat the steps from some times, the button disappears because of the margins which are too small to include it...
I would just suggest to include the form window handle catching in your code. Maybe somebody will need it and not fully understand...
You may be intersted in this thread for adjusting the size of the controls and text along with the userform:
https://www.mrexcel.com/forum/excel-questions/1078144-autosizing-userform-display.html#post5179915
.Font.Size = Split(.Tag, "*")(4) * (Ufrm.InsideWidth) / (dInitWidth <red>* 1.018</red>)
'OPTIONAL: maximize the form full-screen upon first showing.
'========
PostMessage hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0