修改 RichTextBox 中的默认选项卡大小

Modifying default tab size in RichTextBox(修改 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 中的默认选项卡大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Custom Error Queue Name when using EasyNetQ for RabbitMQ?(使用 EasyNetQ for RabbitMQ 时自定义错误队列名称?)
Rabbitmq Ack or Nack, leaving messages on the queue(Rabbitmq Ack 或 Nack,将消息留在队列中)
Wait for a single RabbitMQ message with a timeout(等待一条带有超时的 RabbitMQ 消息)
Setup RabbitMQ consumer in ASP.NET Core application(在 ASP.NET Core 应用程序中设置 RabbitMQ 消费者)
How do I set a number of retry attempts in RabbitMQ?(如何在 RabbitMQ 中设置重试次数?)
WebClient set headers(WebClient 设置标头)