有什么方法可以更改 .NET RichTextBox 中的默认选项卡大小?它目前似乎设置为相当于 8 个空格,这对我来说有点大.
Is there any way to change the default tab size in a .NET RichTextBox? It currently seems to be set to the equivalent of 8 spaces which is kinda large for my taste.
为了澄清,我想将 "的全局默认设置为控件的 4 个空格.据我了解, SelectionTabs 属性要求您首先选择所有文本,然后通过数组选择选项卡宽度.如果必须,我会这样做,但如果可能的话,我宁愿只更改一次全局默认值,这样我就不必每次都这样做.
To clarify, I want to set the global default of " " displays as 4 spaces for the control. From what I can understand, the SelectionTabs property requires you to select all the text first and then the the tab widths via the array. I will do this if I have to, but I would rather just change the global default once, if possible, sot that I don't have to do that every time.
您可以通过设置 SelectionTabs 属性.
You can set it by setting the SelectionTabs property.
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
}
更新:
顺序很重要....
UPDATE:
The sequence matters....
如果您在初始化控件文本之前设置了选项卡,那么您不必在设置选项卡之前选择文本.
If you set the tabs prior to the control's text being initialized, then you don't have to select the text prior to setting the tabs.
例如,在上面的代码中,这将保留带有原始 8 个空格制表位的文本:
For example, in the above code, this will keep the text with the original 8 spaces tab stops:
richTextBox1.Text = " 1 2 3 4";
richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
但这将使用新的:
richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
richTextBox1.Text = " 1 2 3 4";
这篇关于修改 RichTextBox 中的默认选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!