在RichTextBox中修改默认选项卡大小 [英] Modifying default tab size in RichTextBox
问题描述
有没有办法更改默认选项卡大小的.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.
编辑:为了澄清,我想设置\ t的显示为4格控件的全局默认。从我可以理解,在SelectionTabs属性需要你先,然后选择所有文本通过数组的标签宽度。我将做到这一点,如果我必须这样做,但我宁愿只是改变全局默认一次,如果可能的话,SOT,我没有这样做,每一次。
To clarify, I want to set the global default of "\t" 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.
推荐答案
您可以通过设置<一个设置href="http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectiontabs.aspx">SelectionTabs属性。
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.
例如,在上述code,这将让文字与原来的8位制表位:
For example, in the above code, this will keep the text with the original 8 spaces tab stops:
richTextBox1.Text = "\t1\t2\t3\t4";
richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
但是,这将使用新的:
But this will use the new ones:
richTextBox1.SelectionTabs = new int[] { 100, 200, 300, 400 };
richTextBox1.Text = "\t1\t2\t3\t4";
这篇关于在RichTextBox中修改默认选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!