Bring cursor to top in richtextbox after enter then

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Bring cursor to top in richtextbox after enter then

Post by stevens »

Hi,

I have a richtextbox which I like to clear after entering.
So I have an event which works fine $richtextbox.Clear(), but the cursor should be again at top of richtextbox and now is on a second line (because of the enter).

Please advise howto correct that, a full reset of the RichTextbox somehow?
S.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bring cursor to top in richtextbox after enter then

Post by jvierra »

Why are you adding an "enter" to the box?
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Bring cursor to top in richtextbox after enter then

Post by stevens »

Because that's the way I ask an enduser to enter data. The whole design of the form/project is build upon this input by running enter afer input.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bring cursor to top in richtextbox after enter then

Post by jvierra »

What does that have to do with clearing the box? Are you using the enter key to execute the clear method? That doesn't make any sense. Don't mix input methods with control methods.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Bring cursor to top in richtextbox after enter then

Post by stevens »

When enter is done, the textbox should be cleared to enter new text. It's a chatbot form I m making so once text is typed and entered, the textbox should be empty to enter new text.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bring cursor to top in richtextbox after enter then

Post by jvierra »

THat doesn't give us a clue as to what you are doing or how you are trying to do it. If you have a button that executes the "Clear()" method it will completely clear the box.

Note that when you use the enter key to end an input then the focus will move to the next control. If you try to detect the enter as a termination then you are not doing something that can work unless you cancel the event. That would depend on the event as not all events can be cancelled.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Bring cursor to top in richtextbox after enter then

Post by stevens »

Fair enough.
Thanks for your input on the matter.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Bring cursor to top in richtextbox after enter then

Post by stevens »

I posted the script (example of it) here: viewtopic.php?p=82544#p82544
That to clarify why I do use the enter. Would appreciate your input!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Bring cursor to top in richtextbox after enter then

Post by jvierra »

Read this about the args in the event: https://docs.microsoft.com/en-us/dotnet ... gs-handled

You need to add this after the "Clear()" -
$_.Handled = $true

You may also need to change how the box handles the "Enter" character. You shouldn't have to refocus when you are trying to detect that character.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Bring cursor to top in richtextbox after enter then

Post by stevens »

Thanks!
About your remark: not sure howto deal with it differently?
This topic is 1 year and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked