Modifying default tab size in RichTextBox(修改 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.
为了澄清,我想将 "的全局默认设置为控件的 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 中的默认选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:修改 RichTextBox 中的默认选项卡大小
基础教程推荐
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
