文本框控件中的文本缩进
有没有一种简单的方法来缩进多行选择,通过按 tab 键或 shift-tab 来删除 C# 文本框控件 (VS2008) 中每个选定行开头的制表符?
Is there a simple way to indent a multiline selection by pressing the tab-key or shift-tab to remove tabs at the beginning of each selected line in a C# textbox control (VS2008)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下代码片段使用了我编写的两个(简单的)扩展方法(
SelectFullLines
、ReplaceRegex
),但方法应该很清楚:您还需要设置
txtScript.AcceptsTab = 真
。The following snippet uses two (trivial) extensions methods I wrote (
SelectFullLines
,ReplaceRegex
), but the approach should be clear:You also need to set
txtScript.AcceptsTab = True
.也许这实际上很复杂,我不知道。但下面的解决方案给了你一个想法并且基本上可行。您必须自己实现删除,并且我没有真正测试代码。这只是为了让您了解如何做到这一点。
Maybe this is actually complicated, I don't know. But the following solution gives you an idea and basically works. You have to implement the removal yourself and I didn't really test the code. This is just to give you an idea how this can be done.
您可以设置文本框的 AcceptsTab属性设置为
true
。这将允许您在控件中输入制表符。但是,不支持开箱即用地使用 Shift+Tab 删除缩进。您可能必须处理 KeyPress 事件并自行删除插入符号下的制表符。
编辑:我误读了这个问题。要实现诸如 Visual Studio 的缩进/缩进功能之类的功能,请尝试以下操作:
You can set the TextBox' AcceptsTab property to
true
. That will allow you to enter tab characters into the control.Removing indent using Shift+Tab, however, is not supported out of the box. You'll probably have to handle the KeyPress event and remove the tab character under the caret yourself.
EDIT: I misread the question. To achieve something like the indent/dedent feature of Visual Studio, try something like: