我有一个字符串列表,我想用它们填充我的标签
这是我到目前为止所做的,但似乎没有效果
Dim _items() As String = {"Apple", "Orange", "Banana", "Mango"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
label1 = _item
End Sub
这就是我希望输出
的方式答案 0 :(得分:1)
首先,这真的是一个标签吗?它看起来像一个TextBox。
我认为它是一张标签。确保Label在设计器中设置了一些属性以允许多行文本和大尺寸文本:
label1.AutoSize = false
您的问题归结为这两个问题:
这将解决两个问题
Dim _items() As String = {"Apple", "Orange", "Banana", "Mango"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' change the array of strings into a single string delimited with crlf
Dim delimitedString = String.Join(Environment.NewLine, _items)
' set the label's text property to your string
label1.Text = delimitedString
End Sub
答案 1 :(得分:0)
label1.Text = String.Join(vbCrLf, items)