【问题标题】:How to scale controls on a form to fit the form proportionately?如何缩放表单上的控件以按比例适合表单?
【发布时间】:2011-05-18 04:16:10
【问题描述】:

我有一个带有各种分组框、按钮和标签的 Visual Basic 2010 表单。我希望能够最大化表单,但是当我这样做时,控件保持在它们所在的位置并且它们不会随着表单调整大小。我希望他们根据表格按比例调整大小。任何帮助将不胜感激。

【问题讨论】:

  • 从来没有这样的用户界面。但是您可以通过使用 Anchor 属性来获得它,也可以使用底部和右侧的锚点。
  • 好吧,锚可以处理一些事情,但基本的左、右、上和下对于我想要做的事情来说是不够的
  • 我已经发布了一个答案,它给了我很好的结果

标签: vb.net winforms controls scaling


【解决方案1】:

您可以根据窗体的大小设置控件窗体 ResizeEnd 或 Resize 事件的位置和大小。您需要确保表单在最小化或非常小时不会崩溃。

【讨论】:

    【解决方案2】:

    我实际上最终使用表格布局面板来安排所有内容与屏幕大小成比例。如果您的控件布置在网格中,它会很好地工作。

    【讨论】:

      【解决方案3】:

      设form1为表单,

      gb_check 是表单内的组框

      Groupboxheight, location and width 可以相对于表单大小如下进行

       Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
                  gb_chek.Height = (Me.Height * 30) / 100 'what ever be the form height the group box's height is always 30% of the form size
                  gb_chek.Width = (Me.Width * 40) / 100 'what ever be the form width the group box's width is always 40% of the form size
                  gb_chek.Location = New Point((Me.Width) / 18, (Me.Height) / 12)' set the location of the form relative to form size;
       End Sub
      

      如果您在分组框内有控件,则其大小相对于分组框设置

      【讨论】:

        【解决方案4】:

        这是正确的方法!为了正确显示每个屏幕分辨率,请使用 .net 框架中提供的布局!您无需编辑任何边距或其他任何内容。

        【讨论】:

          【解决方案5】:

          Dim res As New SizeF(Screen.PrimaryScreen.WorkingArea.Width / Me.Size.Width, Screen.PrimaryScreen.WorkingArea.Height / Me.Size.Height) Me.Scale(res)

          【讨论】:

            猜你喜欢
            • 2014-06-08
            • 1970-01-01
            • 1970-01-01
            • 2012-10-03
            • 2016-09-27
            • 1970-01-01
            • 1970-01-01
            • 2017-12-09
            • 1970-01-01
            相关资源
            最近更新 更多