【问题标题】:Center a control in another control在另一个控件中居中一个控件
【发布时间】:2014-12-16 15:08:59
【问题描述】:

设置文本值后如何在面板中居中显示标签?

假设我的面板宽 134 像素,标签长 20 个字母。

谢谢你=)

【问题讨论】:

    标签: .net vb.net label panel centering


    【解决方案1】:

    你不需要更改AutoSize

    Label1.Location = New Point(Panel1.Left + CInt((Panel1.Width - Label1.Width) / 2), _
                                Label1.Top)
    

    并且也将其垂直居中:

    Label1.Location = New Point(Panel1.Left + CInt((Panel1.Width - Label1.Width) / 2), _
                                Panel1.Top + CInt((Panel1.Height - Label1.Height) / 2))
    

    【讨论】:

      【解决方案2】:

      仅将文本居中,而不是标签。

      将标签设置为非AutoSized,将其宽度设置为与面板相同的宽度,然后将文本居中:

          With Label1
              .AutoSize = False
              .Width = Panel1.width
              .TextAlign = ContentAlignment.MiddleCenter
          End With
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-14
        相关资源
        最近更新 更多