Textbox Lines Limit

  • Thread starter Thread starter Samuel Shulman
  • Start date Start date
S

Samuel Shulman

Is there any way to put a limit on the number of lines in a textbox? (appart
of number of characters)

Thank you,
Samuel
 
Try counting the number of Returns the user enters, after which stop him
entering
 
I think it can be possible. Though I havnt tried it, but give it a try.

Declare a variable which will keep track of ur no of lines.
Then on the textBox's keydown/keypress event track "Enter" key and then
increment ur variable and check its value against your max no of lines.

Remember Enter key ASCII code is 13.

Thanks.
ag
 
count the number of occurences of environment.newline and take the action
you want to perform


here a small example that could do something after you have more as 5 rows

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

If countsubstrings(TextBox1.Text, Environment.NewLine) = 5 Then

'do your stuff

End If

End Sub

Function countsubstrings(ByVal source As String, ByVal search As String)As
Integer

Dim count As Integer = -1

Dim index As Integer = -1

Do

count += 1

index = source.IndexOf(search, index + 1)

Loop Until index < 0

Return count

End Function



hope to have given you some inspiration



regards


Michel Posseth [MCP]
 
There is a textbox property called lines which returns an array of the text
box lines. You might be able to do something with mytextbox.lines.count.
--
Dennis in Houston


Michel Posseth said:
count the number of occurences of environment.newline and take the action
you want to perform


here a small example that could do something after you have more as 5 rows

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged

If countsubstrings(TextBox1.Text, Environment.NewLine) = 5 Then

'do your stuff

End If

End Sub

Function countsubstrings(ByVal source As String, ByVal search As String)As
Integer

Dim count As Integer = -1

Dim index As Integer = -1

Do

count += 1

index = source.IndexOf(search, index + 1)

Loop Until index < 0

Return count

End Function



hope to have given you some inspiration



regards


Michel Posseth [MCP]
Samuel Shulman said:
Is there any way to put a limit on the number of lines in a textbox?
(appart of number of characters)

Thank you,
Samuel
 
Back
Top