【问题标题】:Control Scaling Problem in Windows 7Windows 7 中的控制缩放问题
【发布时间】:2011-11-26 01:37:54
【问题描述】:

我的 .net winforms 程序中有一些自定义用户控件在用户选择较大的文本大小时无法正确显示。此设置:

我的控件是这样的,

不是这样,

账单到地区和送货到地区都是自定义控件。我不知道这是否会导致问题,但我确实在每个代码中都有代码来帮助扩展电话/传真区域以很好地伸展,就像从账单到控制的这段代码,

    Private Sub panFaxPhone_Resize(sender As Object, e As System.EventArgs) Handles panFaxPhone.Resize
            panFax.Width = (panFaxPhone.Width / 2) - 1
            panPhone.Width = (panFaxPhone.Width / 2) - 1
            panFax.Left = panFaxPhone.Width - panFax.Width
    End Sub

我怎样才能让我的控件大小正确,同时仍然尊重用户对更大文本的选择(我不想只是将 AutoScaleMode 设置为 None)?

更新: 在玩了很长时间之后,似乎是子控件中的锚点有问题。看下图,里面的黑框是打开边框的控件,文本框(如名称)左右锚定,应该拉伸以填充控件,但不要。

【问题讨论】:

    标签: .net windows vb.net winforms windows-7


    【解决方案1】:

    看起来默认控制缩放不适用于锚点。我不知道为什么,也无法解释。但我确实找到了解决办法。请参阅下面我添加到控件的代码。如果您能提供解释,我将不胜感激。

        Private ChildControlScale As Double = 0
        Public Sub New()
    
            ' This call is required by the designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            ChildControlScale = txtAddress.Width / Me.Width
    
        End Sub
    
        Protected Overrides Sub ScaleControl(factor As System.Drawing.SizeF, specified As System.Windows.Forms.BoundsSpecified)
            MyBase.ScaleControl(factor, specified)
            If ChildControlScale <> 0 Then
                For Each ctrl As Control In Me.Controls
                    ctrl.Width = Me.Width * ChildControlScale
                Next
            End If
        End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 2013-03-29
      • 2014-07-24
      • 2011-06-10
      • 2018-02-01
      相关资源
      最近更新 更多