Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8036525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:38:56+00:00 2026-06-05T02:38:56+00:00

Under RichTextBox_TextChanged event, I have if RichTextBox.Lines.Count() > 2 { //Message Box to display

  • 0

Under RichTextBox_TextChanged event, I have

   if RichTextBox.Lines.Count() > 2
   {
      //Message Box to display the user that you are typing more than 2 lines
    }

so what i happens is when i have these data in

 [0] - "East coast road"
 [1]- "New York"

rich text box, when i click Enter, seems it goes into this state

   [0] - "East coast road"
   [1]- "New York"
   [2] -""  

and I get the message pop up box saying can’t have more than 2 lines, however the last line is just an empty line?

How do i handle the line restrictions in rich text box or how do i
ensure that when the user clicks enter I don’t move to the next line
and move to the next line only if there is 1 line in the rich text
box?

This returns count as 3 where in there should be only 2, how do i eliminate that white space next line?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:38:57+00:00Added an answer on June 5, 2026 at 2:38 am

    You have kind of shotgunned the available tags. But this should give you an idea how to do it. The KeyDown event happens before the TextChanged event. So I would intercept the keystroke, check for the Enter Key and if the line count is 2 or greater I would Handle it. Something like this C# winforms example:

    private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter && richTextBox1.Lines.Length >= 2)
            e.Handled = true;
    }
    

    To answer your question on the Handled Property.

    From Link:

    Handled is implemented differently by different controls within Windows Forms. For controls like TextBox which subclass native Win32 controls, it is interpreted to mean that the key message should not be passed to the underlying native control. If you set Handled to true on a TextBox, that control will not pass the key press events to the underlying Win32 text box control, but it will still display the characters that the user typed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a window form containing a richtextbox. Upon button click event, as the
Under VS's external tools settings there is a Use Output Window check box that
Under the user generated posts on my site, I have an Amazon-like rating system:
I have a RichTextBox, and I am wanting to code it, that when the
under The Thumb instruction set in section 1-34 of ARM11TechnicalRefManual it said that: The
Under Windows, I have used a program called Dependency Walker to examine the libraries
I noticed the WinForms RichTextBox has a ZoomFactor property that I assume is exactly
Under windows , we frequently use event to synchronize threads. Under java, is there
Under normal circumstances to authenticate a user in AD, one sends AD the user's
Under what circumstances would java.util.zip.ZipFile.close() throw an IOException? Its method signature indicates that it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.