如何设置动态添加标签的文本对齐方式 [英] how to set text alignment of dynamically added label
本文介绍了如何设置动态添加标签的文本对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置动态添加标签的文本对齐方式我在字符串变量中获取标签名称一个标签在面板中动态添加
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我的名字由:
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
推荐答案
您需要将控件转换为标签:
You need to cast the control to a label:
For Each c As Control In Panel1.Controls
stringVariable = c.name
Dim l As Label = TryCast(c, Label)
If l IsNot Nothing Then
l.TextAlign = ContentAlignment.MiddleCenter
End If
Next
这篇关于如何设置动态添加标签的文本对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文