Creating a rectangular selection in a RichTextBox with an Alt-Left-Mouse scroll?

There are quite a few applications that allow you to select a rectangle or rectangle of text, sweeping the mouse when you press the Alt key. For example, Visual Studio 2010 does this in a code editor. Emacs does this. Winword does this. We all saw it. It seems that there must be a standard template for coding this behavior, but I cannot find it.

I suspect that I am not Googling with the right keywords, since all I get is false hits on the rectangle, Alt-Left, sweep, selection, etc.

I am sure that I can encode it, but this will mean abandoning the usual selection code used, say, in RichTextBox. And that sounds ugly, error prone, and probably more work than it's worth.

Does anyone have a suggestion (be beautiful! :-)) how to do this or an example of how this is done?

UPDATE: I just found this Code Project article that might apply: Column Based Choices

+5
source share
1 answer

RichTextBox is often mistaken for an editor. It is technically possible, you will need a lot of code. The first order is to choose a font with a fixed pitch, such as Courier.

, , . , , SelectionBackColor. MouseDown MouseMove, Control.Modifiers, , ALT. GetCharIndexFromPosition, , . , /, SelectionStart, SelectionLength SelectionBackColor .

, . P/Invoke SendMessage(), WM_SETREDRAW , .

- . RTB, WndProc() WM_COPY, WM_CUT, WM_PASTE. - , , .

, ScintillaNET. , , .

+4

All Articles