在制作使用Alt-鼠标左扫一个RichTextBox一个矩形选区? [英] Making a rectangular selection in a RichTextBox with Alt-Left-Mouse sweep?

查看:116
本文介绍了在制作使用Alt-鼠标左扫一个RichTextBox一个矩形选区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有相当允许您通过在Alt键被按下鼠标扫来选择文本框或矩形几个应用程序。 Visual Studio 2010中执行此操作在代码编辑器,例如。 Emacs的做的。 WINWORD做的。我们都看到了。这似乎是必须有一个标准模式遵循编码这种行为,但我似乎无法找到它。

There are quite a few applications that allow you to select a box or rectangle of text by sweeping with mouse while the Alt key is pressed. Visual Studio 2010 does this in the code editor, for instance. Emacs does it. Winword does it. We've all seen it. It seems like there must be a standard pattern to follow to encode this behavior but I cannot seem to find it.

我怀疑我不是用正确的关键字,所有谷歌搜索我正在上矩形虚假点击,按住Alt键左,扫描,选择等。

I suspect I am not Googling with the correct keywords as all I am getting are false hits on rectangle, Alt-Left, sweep, selection, etc.

我敢肯定,我可以编写它,但它意味着禁用正常在,比方说,RichTextBox的使用选择代码。这听起来很丑陋,很容易出错,可能更多的工作比它的价值。

I'm sure I can code it up but it would mean disabling the normal selection code used in, say, RichTextBox. And that sounds ugly, error prone and probably more work than it is worth.

任何人有一个建议(是不错!:-))如何做到这一点或?例如它是如何做的。

Anybody have a suggestion (be nice! :-) ) of how to do this or an example of how it is done?

更新:我刚刚找到这篇文章的代码项目可能适用的:的列基础的选择

UPDATE: I just found this article on Code Project that might apply: Column based selection

推荐答案

的RichTextBox常被误认为是一个编辑器。这在技术上是可能的,你需要大量的代码。的第一道命令是选择一个固定的间距字体,如快递。

RichTextBox is often mistaken for an editor. It is technically possible, you'll need a lot of code. First order of business is to select a fixed pitch font, like Courier.

主要的问题是,你不能使用选择功能,它总是跨越线。你必须捏造事实,可能使用的SelectionBackColor财产。实施的MouseDown和mousemove事件时,检查Control.Modifiers属性,看看ALT键关闭。使用GetCharIndexFromPosition看到的是被选中的。在移动事件,通过被取消/选中的列和行循环,使用SelectionStart,SelectionLength和的SelectionBackColor财产上色字符。

Chief problem is that you cannot use the selection feature, it always spans lines. You'll have to fake it, possible by using the SelectionBackColor property. Implement the MouseDown and MouseMove events, check the Control.Modifiers property to see if the ALT key is down. Use GetCharIndexFromPosition to see what is being selected. In the move event, loop through the columns and rows that were de/selected, using the SelectionStart, SelectionLength and SelectionBackColor property to colorize characters.

这会闪烁像一个廉价汽车旅馆。的P / Invoke的SendMessage()发送WM_SETREDRAW消息之前和之后,以避免这种情况。

This will flicker like a cheap motel. P/Invoke SendMessage() to send the WM_SETREDRAW message before and after to avoid this.

做好与选择的东西是具有挑战性的。你需要子类RTB所以你可以重写的WndProc()和检测WM_COPY,WM_CUT,WM_PASTE消息。其他随机的问题是自动滚动,当鼠标获得接近控制的顶部或底部以及正在制作另一个选择取消选择。

Doing something with the selection is challenging. You'll need to sub-class RTB so you can override WndProc() and detect the WM_COPY, WM_CUT, WM_PASTE messages. Other random problems is auto-scrolling when the mouse gets close to the top or bottom of the control and unselecting when another selection is being made.

或者你可以使用一个真正的编辑,像ScintillaNET。总括而言,这个答案是不太可能得到许多upvotes的问题。

Or you could use a real editor, like ScintillaNET. All and all, this answer is unlikely to get as many upvotes as the question.

这篇关于在制作使用Alt-鼠标左扫一个RichTextBox一个矩形选区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆