xsharp.eu • Winforms: how to use cursor keys to select text?
Page 1 of 1

Winforms: how to use cursor keys to select text?

Posted: Thu Apr 20, 2023 10:47 pm
by ic2
In VO we use a MultiLineEdit control to select multiple text fragments from the content. Each time a user has selected some text they click a button and then can continue to select the next fragment or finish. The user can do that with the mouse but also scroll down with cursor keys and select text with the usual combination like Ctrl cursor.

Our X# converted-prg-in-progress uses Winforms and I found out that nor a TextBox, nor a RichEdit control seem to do anything with cursor keys. Not for selecting and not for browsing down through the text.

Is there any way to enable that, or otherwise an alternative control where this does work?

Dick

Winforms: how to use cursor keys to select text?

Posted: Fri Apr 21, 2023 7:28 am
by Chris
Hi Dick,

for the TextBox, you can use Select(start,length) to select some text. Also with ScrollToCaret(), you can make it scroll so that the caret/start of selected text is visible. Finally, with HideSelection := FALSE you can make the selected text be always visible as selected, even if the control doesn't currently have focus.

https://learn.microsoft.com/en-us/dotne ... work-4.8.1
https://learn.microsoft.com/en-us/dotne ... work-4.8.1
https://learn.microsoft.com/en-us/dotne ... work-4.8.1

.

Winforms: how to use cursor keys to select text?

Posted: Fri Apr 21, 2023 7:51 am
by ic2
Hello Chris,

Thanks for your reply, but selecting text from the program is not the problem; that works.

The problem is that a user can't use cursor movement keys to select text (e.g. Shift-Cursor) or use the cursor keys to scroll up/down through text. That can only be done with the mouse.

Dick

Winforms: how to use cursor keys to select text?

Posted: Fri Apr 21, 2023 7:55 am
by Chris
Hi Dick,

If that was the case, there would be millions of very angry people throwing their .Net apps out of the Window(s) :)

That does work fine, maybe you have introduced a method intercepting and handling key presses of your textboxes which accidentally "eats" the shift/cursor key presses?

Winforms: how to use cursor keys to select text?

Posted: Fri Apr 21, 2023 1:07 pm
by ic2
Hello Chris,
Chris post=25988 userid=313 wrote: If that was the case, there would be millions of very angry people throwing their .Net apps out of the Window(s)
There are many other reasons to do so but still people keep using the .Net apps :lol:

But it seems to work as it should now. Only issue for me is that I have no idea why it didn't earlier....

Dick