I am using the winforms textbox with multiline option ON. I want to limit the number of lines that can be entered in it. User should not be able to enter lines more than that.
How can I achieve that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to check for
txtbox.Lines.LengthYou need to handle this for 2 scenarios: 1. User is typing in the textbox 2. User has pasted text in the textbox
User typing in textbox
You need to handle the key press event of the text box to prevent user from entering more lines when max lines are exceeded.
I have tested the above code. It works as desired.
User pastes some text in the textbox
To prevent the user from pasting more than the max lines, you can code the text changed event handler: