When AutoCompleteCustomSource property of Windows.Forms.TextBox is set, list of variants appears during the entering in textbox.
One can either use a mouse to point and click on one of the variants or choose with up-down buttons and press Enter.
You can also press enter whenever you like.
The gist of a problem is, when the selection with mouse is made, KeyDown (KeyUp, KeyPress) event(s) is(are) raised exactly as if an Enter key was pressed on the keyboard.
How can i determine what really happened and handle selection using mouse curor and press of the Enter key differently?
I solved this issue by tracking mouse and keyboard events of the text box. The resulting functionality was similar to the browser address bar. I can't get to the source code right now but it was basic logic around MouseDown, MouseUp, KeyDown, KeyUp whilue storing their values in variables.
Related
I'm trying to make a button change its fore color when we press a key. Like button's name is "A" and we press A it changes the fore color into red, then we release the key it turns back to its default color. But I can't find any such event.
Thank you! :D
It's KeyDown, KeyPress, and KeyUp event you should use.
Refer to this link.
http://csharp.net-informations.com/gui/key-press-cs.htm
If you want to capture a key typed anywhere on a form, you can use Keydown, KeyPress and KeyUp like ydoow said, but you will also have to set the form's KeyPreviewproperty to true to make sure your events are raised even if a key is typed while in a specific control.
I have a listview with some rows.
These rows contain a textbox.
I would like the listview to not change items when the user presses ↑ or ↓ on the keyboard if they are focused in a textbox.
Reasoning: One of the textboxes has a popup that shows some autocomplete results, it is common for the user to simply press ↓ on the keyboard to move through the suggestions. This is currently not working, as pressing ↓ is instead moving the users selection to the line below within the listview.
This is made harder due to the fact that winrt listviews do not have the PreviewKeyDown event.
Any ideas how i might be able to solve this problem?
I think the solution would be to check, in the keydown event, if the pop up is open, and, if it is, to change the pop up selection, instead.
Is there a way in silverlight to detect when a lost focus event is triggered if this
happens because the tab key is pressed or the user presses a mouse button on another control.
This is what i want to achieve:
I have a RadGridView with 1 row. In the last column i have a numeric input, when
an user tabs out of this control, a new row should be added to the sourcecollection in the viewmodel, this automaticly adds a new row to the grid, then the first column on this row should have focus and the dropdownlist in the celledittemplate should be opened.
When i use the lost focus event adding the new row works fine, though this also works when i don't use tab to unfocus the control. Also, the first column on the new row is not selected, it somehow
gives focus to row 0 column 0.
Ok, inspired by the answer Dipak gave I came up with a slightly different solution,
I handled the Gridviews keydown and keyup events, keydown sets a bool to true, keyup to false.
the execution sequence fortunately is keydown, lostfocus, keyup
so in the lost focus event I only need to check wether the bool is true;
strangely enough the keyup event is not always triggered, but since the lostfocus is
I set the bool to false there also.
yes you can trace it, Provided you have implemented mouse up/down event on each focusable element on your screen. You will have flag to check if mouse preview event up/down happen on any element, if not then its TAB key which cause lost focus.
This is work around if some one not suggest proper solution.
I have a feature request that when a ComboBox is 'clicked into' that it clears the text so that the user can start entering in new data to search. Does anyone know of a way to hook into this? The 'click' event is raised on when the text is clicked as well as when the drop down arrow is also clicked (which opens up the drop down with items). I only want it to happen on the first, not the latter.
Right now I'm capturing the click event and filtering on the DroppedDown property like so:
if(!comboBox.DroppedDown)
{
// clear selection
}
This seems to work most of the time, but bugs out frequently as well... so its not 100%.
If anyone knows of a proper way to do this I would appreciate!
Don't handle the click event. For one thing, it won't fire if the user tabs the focus into the control. Use the Enter event which fires when the control receives focus. And rather than clearing text you should just select it all which will give the best of both worlds:
1) The user can start entering new text which will clear any old text or
2) tab past the control and leave the contained text as it was.
If you always remove the previous text you may anger users.
Try the "Enter" event. It happens when a control gains focus on the form.
I am using maskedTextBox.SelectAll() to highlight the text in the MaskedTextBox in the Enter and MouseDown events.
It works when I use the mouse, but I go to that textbox by pressing the Tab key, it does not work.
What am I missing here?
Have you tried the GotFocus event?
When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl.ActiveControl property to the current form, focus events occur in the following order:
It then goes on to list the events that are fired. It looks like this fires when the mouse is used so you might only need this handler.