問題描述
有什么方法可以更改 .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模板網!