我创建了一个程序,它读取文本文件,然后将文本上的每个字符转换为标签。似乎当文本文件过多时,程序滞后或不显示标签或加载太长时间。有没有办法让它更快或避免滞后。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Drawing()
Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText(TextBox1.Text)
RichTextBox1.Text = fileReader
'MsgBox(fileReader)
End Sub
Private Sub Drawing()
Dim i, x, y As Integer
y = 0
x = 0
For i = 0 To RichTextBox1.TextLength - 1
If RichTextBox1.Text.Chars(i) = Convert.ToChar(&HA) Then
y = y + 16
x = 0
Else
Dim lbl As New Label
lbl.Name = "lbl"
lbl.Size = New System.Drawing.Size(15, 15) 'set your size (if required)
lbl.Text = RichTextBox1.Text.Chars(i) 'set the text for your label
lbl.Location = New System.Drawing.Point(x, y) 'set your location
ToolTip1.SetToolTip(lbl, lbl.Text)
lbl.BackColor = Color.Red
Panel1.Controls.Add(lbl) 'add your new control to your forms control collection
x = x + 16
End If
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Panel1.Width = Panel1.Width + 10
Panel1.Height = Panel1.Height + 10
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Panel1.Width = Panel1.Width - 10
Panel1.Height = Panel1.Height - 10
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim dialog As New OpenFileDialog()
If DialogResult.OK = dialog.ShowDialog Then
TextBox1.Text = dialog.FileName
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Drawing()
End Sub
结束班
答案 0 :(得分:0)
我真的不明白你要做什么,但你可能想暂停布局,直到完成这个过程。这将完成绘图,而不会在添加所有这些标签时更新UI或表单。加载标签后,它可以一次性绘制整个标签。
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.SuspendLayout()
Drawing()
Me.ResumeLayout(True)
End Sub