richTextBox中的制表符间距 [英] Tab spacing in richTextBox

查看:172
本文介绍了richTextBox中的制表符间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个文字处理器来学习一些东西. (顺便说一下,这是在C#中)

无论如何,我希望用户能够在richTextBox中按下Tab键,以便像在单词中创建一个空格...

我尝试了KeyDown事件,但是它不响应Tab(它的值制表到了KeyDown事件之前的下一个控件).

无论如何,我并不是真的需要它来创建网格,所以说起来就像用文字说的那样,我只是希望能够从KeyDown选项卡中触发事件. (也许我想在文本中添加5个空格来模拟制表符空间).
像这样:

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:

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!

推荐答案

将属性窗口中的"AcceptsTab"属性更改为true
Change "AcceptsTab" property in the property window to true


这篇关于richTextBox中的制表符间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆