RichTextBox and tab key

2019-06-16 10:19发布

问题:

I created a richTextBox and i noticed that when I press Tab key it is not doing anything. It is suppose to do some space but it do not.

How can i access it?

回答1:

By default pressing tab moves focus to the next control. Setting AcceptsTab property of the RichTextBox to true allows the RichTextBox to accept tab characters.

See this MSDN article on the AcceptsTab property.



回答2:

First you need to set following properties of Richtextbox

richTextBox.Multiline = true;
richTextBox.AcceptsTab = true;

And in the keypress event of richtextbox you need to do following

if (e.KeyChar == 9)
{
    e.Handled = false;
}


标签: c# forms