vb.net 如何设置动态添加标签的文本对齐方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13658310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:24:30  来源:igfitidea点击:

how to set text alignment of dynamically added label

vb.netvisual-studiovisual-studio-2005text-alignment

提问by Dandy

how to set text alignment of dynamically added label where i am getting name of label in string variable one label is dynamically added in panel

如何设置动态添加标签的文本对齐方式,其中我在字符串变量中获取标签名称 面板中动态添加了一个标签

  Dim instance As New Label
  Dim stringVariable As String

on form load event ::

关于表单加载事件 ::

    instance.Location = New Point(15, 15)
    instance.Size = New Size(60, 30)
    instance.BorderStyle = BorderStyle.FixedSingle
    instance.AutoSize = False
    instance.Text = "LABEL1"
    Me.Panel1.Controls.Add(instance)

i am getting name by:

我通过以下方式获得名字:

    for each c as control in Panel1.Controls
    stringVariable=c.name
    next

but its not possible to

但它不可能

   Me.Panel1.Controls(stringVariable).textalign ??????
   it does not show text align property

please help

请帮忙

回答by Steve

DirectCast(Me.Panel1.Controls("Label1"), Label).TextAlign = ContentAlignment.TopRight

回答by user8446655

I found that these values will set TextAlign

我发现这些值会设置 TextAlign

Public pTop_Center As Long = 2
Public pMiddle_Center As Long = 32
Public pBotton_Center = 512

 btn.TextAlign = pBotton_Center