Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm making a word processor to learn some things. (This is in C# by the way)

Anyway I want the user to be able to press Tab in the richTextBox in order to create a space like in word...

I have tried the KeyDown event but it does not respond to Tab (it values tabbing to the next control before KeyDown event).

Anyway I don't really need it to create a grid so to speak like in word, I just would like to be able to trigger events from the tab KeyDown. (Maybe I'd like it to just add 5 blank spaces in the text to simulate the tab space).
Like this:
C#
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Tab)
    {
        MessageBox.Show("it worked!");
        richTextBox1.Text = richTextBox1.Text+ "     ";
    }
}


If anyone knows any way to achieve this or help me in any way I'd like that. Or if I explained it not clearly you can ask me to rephrase things. Thanks in advance!
Posted
Updated 10-Jan-12 9:59am
v3

1 solution

Change "AcceptsTab" property in the property window to true
 
Share this answer
 
Comments
Joel Whatley- 11-Jan-12 11:07am    
oh... HAHA what a simple solution! Thanks!!

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