Is there any way to catch the Up/Down arrow keys in a WPF TextBox (System.Windows.Controls.Textbox) and allow them to alter the text? I've read about overiding the ProcessCmdKey method for a Windows Forms TextBox (System.Windows.Forms.TextBox), and it worked fine, but that TextBox is not nearly as flexible as the WPF one. Is there a similar method to accomplish this without having to use the old Windows Forms TextBox?
For my example, I have a TextBox that has a numeric text-mask. I want to be able increase/decrease the numeric value by using the up and down arrow keys.
You could add event handlers to KeyUp and/or KeyDown, if that doesn't get what you need, using PreviewKeyUp and/or PreviewKeyDown should.
Related
I am trying to create user controls on a simple number sliding game. Instead of using traditional click interface I wanted to use the keyboard but i cant find anyway to bind specific keys to specific buttons and I don't if it is possible to create a keyboard button press event.
is there a way to code a keyboard button press event into the program?
There sure is, in the button click event handler just add a call to this API:
https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(v=vs.110).aspx
I want to remove the flashing dash from a TextBox when the user presses it and to stop the user from being give the option to select and copy text.
Is this possible?
Depending on what you need exactly, there are many ways you can achieve this.
Call Clipboard.SetText("") whenever GotFocus and LostFocus events are triggered.
Override SelectionChanged and do e.Handled = true.
Create your own custom control by inheriting TextBox, set a custom Template, and manually add/remove characters for every KeyDown event.
There doesn't seem to be a way to change the flashing caret/cursor on Windows Universal apps, and there is no way to disable the clipboard either.
Is there any way to define a style/trigger/template that will cause a textbox to lose focus once the Enter key is pressed? Preferably, without using any code...
Thanks!
No, there's nothing baked into WPF to do that. You'd have to add some sort of custom code to look for the Enter key and move the focus manually.
The easiest way would be to use an attached behavior. You could then turn this feature on for all or some of the TextBoxes.
I'm wondering how to filter the input of a .NET textbox.
I already know that I could listen for the KeyDown event and intercept the key, but that won't filter pasted strings by a right-click menu or a CTRL+V.
I also don't wan't to completely disable the possibility of pasting of characters in the textbox. The paste action should be cancelled whenever it contains one or more invalid characters.
Finally, I'd like to display a notification balloon whenever invalid characters are either entered or pasted.
μTorrent already has this exact behavior:
How can I achieve this functionality in C# ?
TextChanged event - Seems like a good call.
You can spawn your own baloon or ToolTip on any control you want to show a detailed feedback to the user
It seems like a combination of KeyPress, TextChanged, Validating, and Validated events should work for your purposes.
My custom Control displays a TextBox when a key is pressed (basically to allow for numeric input). It's easy enough to show the TextBox from inside the KeyDown event on the main control, but how do I pump the keypress into the textbox?
Why dont you keep a buffer ( a variable) to store the value of KeyPress and after the TextBox is Enabled, update the value?
You can use the KeyValue of the KeyEventArgs parameter (sent to the method handling the keydown event of your user control).
Using that you can send the first key to the textbox and then move the focus to the textbox like suggested before.
Hope I understood you well.