简体   繁体   English

VBA:包含元素的用户窗体如何按比例缩放以保持关系?

[英]VBA: How can UserForms with the elements contained be scaled proportionally to maintain the relations?

How can a UserForm with all contained elements be scaled proportionally?如何按比例缩放包含所有元素的用户窗体?

I have a function to scale the UserForm itself.我有一个 function 来缩放 UserForm 本身。 However, the inner elements (head, body) do not scale with it and are therefore shifted and the size no longer fits.但是,内部元素(头部、身体)不会随其缩放,因此会移动并且尺寸不再适合。

I have created the UserForm with the graphical tool.我已经使用图形工具创建了用户窗体。 I'm looking for a way to group the elements like in PowerPoint (they are then all scaled proportionally when resized so that the relations are maintained).我正在寻找一种方法来像在 PowerPoint 中那样对元素进行分组(然后在调整大小时,它们都会按比例缩放,以便保持关系)。

Thanks a lot非常感谢

I have tried to scale all elements individually, but this is very cumbersome, error prone and in my opinion bad style.我试图单独缩放所有元素,但这非常麻烦,容易出错,而且在我看来是糟糕的风格。

I tried to work with one frame.我试着用一个框架工作。

There is no build-in method to zoom a form.没有用于缩放表单的内置方法。 As already mentioned in the comments, you can play around by modifying the left, top (and width and height) properties of the controls.正如评论中已经提到的,您可以通过修改控件的左侧、顶部(以及宽度和高度)属性来进行操作。 You should also change the font size of controls (if they have any).您还应该更改控件的字体大小(如果有的话)。

The following gives you an idea how this could work:以下内容让您了解这是如何工作的:

Const ZoomStep = 1.1

Private Sub buttonLarger_Click()
    zoomForm ZoomStep
End Sub

Private Sub buttonSmaller_Click()
    zoomForm 1 / ZoomStep
End Sub

Sub zoomForm(factor As Double)
    Me.left = Me.left * factor
    Me.top = Me.top * factor
    Me.Width = Me.Width * factor
    Me.height = Me.height * factor
    
    Dim ctrl As Control
    For Each ctrl In Me.Controls
        ctrl.left = ctrl.left * factor
        ctrl.top = ctrl.top * factor
        ctrl.Width = ctrl.Width * factor
        ctrl.height = ctrl.height * factor
        On Error Resume Next  ' Prevent runtime error for controls w/o font
        ctrl.Font.Size = ctrl.Font.Size * factor
        On Error GoTo 0
    Next
End Sub

However, this has of course some limitations.然而,这当然有一些限制。 Checkboxes and Radiobuttons for example don't size (only the caption).例如,复选框和单选按钮不调整大小(仅标题)。 Buttons need some space around the caption and if you make the controls smaller, the caption may get unreadable.按钮在标题周围需要一些空间,如果您将控件变小,标题可能会变得不可读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM