Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want To Focus To Another Object From Rich Text Box When It Reach The Third Line By Pressing
Enter Key
Eg,
......... Press Enter
......... Press Enter
......... Press Enter (At This Point)
Focus To Another Object like Combobox Or Text Box

How To Do This..?
Thanks
Posted

1 solution

You can hook into the PreviewKeyDownEvent on your RichTextBox and then focus the next control if the pressed key is Enter and the RichTextBox has three lines;

C#
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {

    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void richTextBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {

            if (e.KeyCode == Keys.Enter && richTextBox1.Lines.Count() == 3)
            {
                button1.Focus();
            }
        }
    }
}


Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900