Ciao a tutti!
nel mio programmino (che vuole essere simile ad un editor di testo), ho fatto in modo che cliccando un bottone (nel menubar) si apra una nuova scheda con all'interno un nuovo richtextbox, fin qua tutto bene. Però, alla prima scheda (senza cliccare sul bottone) mi permette di numerare le righe che ho fatto, mentre nelle altre schede, non me lo fà.
questo è il listato per creare una nuova scheda e tutto:
codice:
Public Sub newtabStreep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles newStrp.Click
Dim count As Integer
Dim sc As Integer
sc = tabcontrol.TabCount
count = tabcontrol.TabPages.Count
tabcontrol.TabPages.Add("<newfile" & count + 1 & ">")
tabcontrol.SelectedIndex = count.ToString
'
'RichTextBox
'
Dim rich As New RichTextBox
rich.Height = 499
rich.Width = 724
rich.Parent = tabcontrol.TabPages.Item(count)
rich.Location = New System.Drawing.Point(79, 3)
rich.AutoWordSelection = True
rich.BorderStyle = BorderStyle.None
rich.Dock = DockStyle.Fill
rich.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
rich.SendToBack()
rich.TabIndex = 0
'
'TextBox
'
Dim txt As New TextBox
txt.BackColor = Color.Gainsboro
txt.Parent = tabcontrol.TabPages.Item(count)
txt.BorderStyle = BorderStyle.None
txt.Dock = DockStyle.Left
txt.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
txt.Location = New System.Drawing.Point(3, 3)
txt.Multiline = True
txt.ReadOnly = True
txt.Size = New System.Drawing.Size(76, 499)
txt.TextAlign = HorizontalAlignment.Center
txt.MaxLength = 2147483647
txt.SendToBack()
txt.TabIndex = 1
End Sub
mentre questo è il listato per visualizzare le righe correnti del richtextbox:
codice:
Private Sub richtxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles richtxt.TextChanged
Dim ln As Integer
ln = richtxt.Lines.Length
lineTxt.Clear() 'elimina testo presente (numeri righe).
For i As Integer = 1 To ln 'moltiplica da 1 a numero di righe di richtxt.
lineTxt.AppendText(i.ToString + vbCrLf) 'aggiunge il numero di righe + a capo.
Next
If richtxt.Lines.Length = 0 Then
lineTxt.Text = "1" + vbCrLf 'se il n di righe di richtxt è zero,aggiunge a linetxt uno.
End If
End Sub
in parole povere, vorrei sapere come fare a numerare le righe del richtextbox, quando questo viene automaticamente aggiunto tramite codice..
spero abbiate capito..ciao!