Hello all,

I have a form that has a Timer and a label and a RichTextBox.
What I am trying to figure out is how to get the Label to say how many more characters are left in the TextBox.

Here is what I have.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
	Label1.Text = (RichTextBox1.MaxLength)
End Sub

It does work w/ the max length but when I type it does not change.

Plz Help :)

Dani AI

Generated

Short version: drop the Timer and update the label from the RichTextBox's TextChanged event (as suggested). TextChanged fires for typing, paste and programmatic changes, so it keeps the count accurate without polling.

Here’s a small, practical variant that also handles the “no limit” (MaxLength = 0) case, clamps negative values to zero, and pluralizes the word “character”:

Private Sub RichTextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RichTextBox1.TextChanged
    Dim maxLen As Integer = RichTextBox1.MaxLength
    If maxLen = 0 Then
        Label1.Text = "No limit"
        Return
    End If

    Dim left As Integer = Math.Max(0, maxLen - RichTextBox1.TextLength)
    Label1.Text = String.Format("{0} character{1} left", left, If(left = 1, "", "s"))
End Sub

Troubleshooting and tips:

  • Verify MaxLength is set (designer or code). Default is 0 (unlimited).
  • If the label doesn't update, make sure the handler is properly wired (the Handles clause or AddHandler).
  • If you used a non-UI timer (System.Timers or Threading.Timer), you must marshal updates to the UI thread—better to remove the timer entirely.
  • TextChanged covers paste and programmatic changes; if you need to count visible characters differently (e.g., treat CR/LF specially, or count bytes for a protocol), compute the metric from RichTextBox.Text instead of relying solely on TextLength.

This keeps the UI responsive and the remaining-character display accurate for everyday use.

Recommended Answers

All 2 Replies

Use the _TextChanged event of the RichTextBox.

Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
        Label1.Text = (RichTextBox1.MaxLength - RichTextBox1.TextLength).ToString
    End Sub

Oh, okay. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.