2014-02-12 51 views
0

我創建了一個讀取文本文件的程序,然後將文本上的每個字符轉換爲標籤。似乎文本文件太多,程序滯後或不顯示標籤或加載時間過長。有沒有辦法讓它更快或避免滯後。由於標籤太大而導致vb滯後

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

我真的不明白你正在嘗試做的,但你可能要直到工藝,以暫停佈局。這將完成圖形,而不會更新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 
+0

我正在嘗試製作多個標籤。它似乎在生產至少1000個標籤上工作,但我需要生產5000-1000個標籤,這給我一個錯誤。 – user3299825