X - Key as a shortcut creates problem when typing.
-
I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.
-
I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.
Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.
-
I have to add one functionality in my Windows application. When user presses X key, it should do some function by calling routine. However when user is typing something on a form(ex. in textbox), this event should not be fired. Currently due to this event handler code, user is unable to type X key becoz it is calling X key routine. Any solution of this problem? Thanks.
Use alt+x ? Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...) This might be off help: form.ActiveControl
-
Maybe you could set a boolean flag which gets toggled when the user enters/leaves the textboxes on your form. The x key routine would then check the state of the boolean flag which would determine if the event should go ahead or not.
Thanks Liqz, The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here. I do not want to change all the user controls but I want to change only main form. Thanks.
-
Thanks Liqz, The situation is there is one main form and depending on menu items selection, it is loading user controls on main form, which comes from multiple solutions. So there are many solutions and lots of user controls are taking part here. I do not want to change all the user controls but I want to change only main form. Thanks.
Take a look at Tom's post below, it is actually a better solution than mine, I was unaware of the ActiveControl method. Using that method you can get the type of the active control, then if the type of active control is a text box, don't do the x key function.
-
Use alt+x ? Other than that in your function (that is called by the event handler on pressing x) check if the current active control is one where the user can type in (textbox, richtextbox,...) This might be off help: form.ActiveControl
Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.
-
Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.
Hi, the KeyDown event offers a KeyEventArgs object containing information about the most recent key, but also the current state of the modifier keys such as Alt, Control, Shift. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Thanks Tom, I looked for X key combination with Alt key but it is returning me only Alt key and not with combination of other key with Alt so i am unable to trap event for Alt+X key combination. Also I looked on ActiveControl but the deal is I have layers of controls like this: Bottom to top Form User Control Split control User control Textbox and other controls. When I tried to get active control, it returns me "System.Windows.Forms.SplitContainer" and not individual controls. Any help please? Thanks.
If the alt+x way is a valid way to go for you I would do it that way, since you have usercontrols the activecontrol will most likly never be to accurate. This code works fine for me:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Alt = True And e.KeyCode = Keys.X Then
MessageBox.Show("success")
End If
End SubProperty 'Keypreview' from the form set to true If you don't get it working like that I suggest you create a menustrip on the form, add a dummy menu, in the properties of that menu add a shortcut (alt + x), set the property 'visible' from the menustrip to false and do your function in the click event of the menu. (always works that way)