Bring cursor to top in richtextbox after enter then
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.
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.
Re: Bring cursor to top in richtextbox after enter then
Normally we would not use the "KeyDown" event as it is intended for key flag detection. For basic character detection we would use "KeyPress" which is cancelable. Both will work but using the intended event prevents future issues as code changes. I recommend learning the basics of WinForms event handling and event cascade order. KeyDown, KeyPress and KeyUp are all executed whenever a key is pressed. This is true for most user activated event streams. The breakdown is intended to solve specific issues of coding controls and forms. Once you understand this then a huge chunk of understanding of coding with WinForms will become obvious.
Re: Bring cursor to top in richtextbox after enter then
I just realized that the only way to cancel a key in an RTB is to do it in the "KeyUp" event.
There is no need to use an RTB for what you are doing. This is part of your problem. Never use a control that is more complex than needed. If you are not using RTF features, then just use a textbox. It will save you a lot of headaches in the longer term.
There is no need to use an RTB for what you are doing. This is part of your problem. Never use a control that is more complex than needed. If you are not using RTF features, then just use a textbox. It will save you a lot of headaches in the longer term.
Re: Bring cursor to top in richtextbox after enter then
Note: tried a textbox instead of a richtextbox but I don't see any difference. Now the cursor even doesn't go to top once entered (in the textbox).
I then added
$textboxInput.Text = ''
$textboxInput.Clear()
$_.Handled = $true
But cursor doesn't go to top at all now. So I better stick to richtextbox I guess.
I then added
$textboxInput.Text = ''
$textboxInput.Clear()
$_.Handled = $true
But cursor doesn't go to top at all now. So I better stick to richtextbox I guess.
Re: Bring cursor to top in richtextbox after enter then
Works fine for me. You keep jumping from one thing to another and because you are confused about how it works you keep missing the clues.
Here is a simple demo.
Here is a simple demo.
- Attachments
-
- Demo-TextClear.psf
- (14.27 KiB) Downloaded 45 times
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Bring cursor to top in richtextbox after enter then
Place caret in RTB:
https://social.msdn.microsoft.com/Forum ... ?forum=wpf
Place caret in a TextBox
https://www.c-sharpcorner.com/UploadFil ... n-textbox/
https://social.msdn.microsoft.com/Forum ... ?forum=wpf
Place caret in a TextBox
https://www.c-sharpcorner.com/UploadFil ... n-textbox/
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Bring cursor to top in richtextbox after enter then
Alex, that does not remove the "Enter" character. It just moves the caret. Doing that repeatedly will end up filling the box with "Enter" characters or, if using "Clear()" will always leave an extra "Enter" character.
Look at my demo. It is the best way and in most cases the only way to fully clear a textbox or RTB. It is also the easiest way.
Look at my demo. It is the best way and in most cases the only way to fully clear a textbox or RTB. It is also the easiest way.
- Alexander Riedel
- Posts: 8488
- Last visit: Tue Apr 16, 2024 8:42 am
- Been upvoted: 37 times
Re: Bring cursor to top in richtextbox after enter then
I know. But there also seemed confusion as to how to place the caret.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Bring cursor to top in richtextbox after enter then
Alex, that was because of a poorly asked question which had me confused for a while too. What Steven was actually asking was how to clear a box and both have the "Enter" character left in the box. That is why it was not at the to-left but one line down always.
Part of my problem was my poor decoding of the question and then trying to understand why it was an issue. Once I had the right question then the answer was obvious. I also thought to try and get Steve to look first at the documentation for the control and to approach the code from the event stream and not from linear methods which only work in a console script.
Getting techs new to coding in WinForms is hard because techs are not programmers and definitely not Windows programmers. Windows is an object state system. Scripts in the past have not needed to consider asynchronous execution which is what happens at a PS prompt. WinForms just removes all simplicity of a recipe-like code execution because events are async and the order of things from the keyboard, mouse and other devices generate multiple messages from the Windows system which are dispatched as events. Once a coder sees this and checks the event descriptions and examples then things tend to become clear fairly quickly.
Techs do not seem to like to read. All of my techs were like that but, with a little encouragement, they realized that the documentation was an easier and faster way to start to solve almost any problem. The docs also give us more info as we review events, methods and properties repeatedly. My poor techs were stuck carting around a pile of manuals although we usually cached manuals at the customer sites. Still, paper is a pain when looking things up. Computers and search engines turn lookups into a near instantaneous operation. I still rely on docs even with WinForms even though I have been building windows since Windows 0.9. You know, assembler and Borland C. At the Windows 2.0 release we acquired an IDE and compiler called Actor. The first object development system on Windows as far as I can tell. It was similar to using the Net Framework and Sapien PSS although without all of the Sapien conveniences.
Part of my problem was my poor decoding of the question and then trying to understand why it was an issue. Once I had the right question then the answer was obvious. I also thought to try and get Steve to look first at the documentation for the control and to approach the code from the event stream and not from linear methods which only work in a console script.
Getting techs new to coding in WinForms is hard because techs are not programmers and definitely not Windows programmers. Windows is an object state system. Scripts in the past have not needed to consider asynchronous execution which is what happens at a PS prompt. WinForms just removes all simplicity of a recipe-like code execution because events are async and the order of things from the keyboard, mouse and other devices generate multiple messages from the Windows system which are dispatched as events. Once a coder sees this and checks the event descriptions and examples then things tend to become clear fairly quickly.
Techs do not seem to like to read. All of my techs were like that but, with a little encouragement, they realized that the documentation was an easier and faster way to start to solve almost any problem. The docs also give us more info as we review events, methods and properties repeatedly. My poor techs were stuck carting around a pile of manuals although we usually cached manuals at the customer sites. Still, paper is a pain when looking things up. Computers and search engines turn lookups into a near instantaneous operation. I still rely on docs even with WinForms even though I have been building windows since Windows 0.9. You know, assembler and Borland C. At the Windows 2.0 release we acquired an IDE and compiler called Actor. The first object development system on Windows as far as I can tell. It was similar to using the Net Framework and Sapien PSS although without all of the Sapien conveniences.