Reputation: 184
I've been struggling way too much with simple things, like the one i'm posting.
I'm developing a UI in vb.net that gathers some information from a machine. The information is collected to a TextBox:
Private Sub ReceivedText(ByVal [text] As String)
If Me.TextBox2.InvokeRequired Then
Dim x As New SetTextCallBlack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.TextBox2.Text &= [text]
End If
End Sub
Then i gather that information either to a datagridview or to some labels to display simple information.
Sub dgv()
Dim sup2 = TextBox2.Text.Replace("#", "").Replace(">", " "c)
Dim sup() = sup2.Split(" "c, "#", vbCrLf, vbTab)
With DataGridView1
.Rows(0).Cells(0).Value = sup(1).ToString
.Rows(0).Cells(1).Value = sup(7).ToString
.Rows(0).Cells(3).Value = sup(4).ToString
End With
Button5.Enabled = True
Button6.Enabled = True
End Sub
This works just fine !!!
But when i try to populate the labels, with the code below, it just won't work!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Thread.Sleep(250)
Dim final = TextBox2.Text.Replace("#", "").Replace("SN", " "c)
Dim final2() = final.Split(" "c, "#", vbCrLf, vbTab)
Label1.Text = final2(0).ToString
Textbox2.Text= final2(0).ToString
End Sub
Can someone help me? The label gets no text.. and the textbox gets all of it.
Btw, the textbox is multiline and if i paste the text in microsoft word it comes with tabs and extra spaces.
Edit: printscreen from microsoft word below [ related to Multiline Textbox to Datagridview ]
Edit2: This is so strange ..
If i do this
Label1.Text = "Testing" & TextBox2.Text
it only shows "Testing" on the label..
Upvotes: 1
Views: 211
Reputation: 28403
If you set the label to AutoSize, it will automatically grow with whatever text you put in it. (This includes vertical growth.)
Before assign
value to the label1
,
Use the below code
Label1.MaximumSize = new Size(100, 0)
Label1.AutoSize = true
your code would be like
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Thread.Sleep(250)
Dim final = TextBox2.Text.Replace("#", "").Replace("SN", " "c)
Dim final2() = final.Split(" "c, "#", vbCrLf, vbTab)
Label1.MaximumSize = new Size(100, 0)
Label1.AutoSize = true
Label1.Text = final2(0).ToString
Textbox2.Text= final2(0).ToString
End Sub
Upvotes: 0