Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toolstrip Item is being triggered by "Enter Key"...

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
0
0
US
Ok, so I'm having a slight issue and I can't seem to figure it out.

Here is the setup...
Toolstrip is inside of a toolstrip container on a windows form. Those toolstrip buttons cause different custom controls to load into the main pane on the toolstrip container.

For some reason when a combobox (which is inside a custom control loaded in the main pane) is active and the enter key is depressed... it's triggering one of my toolstrip buttons to run through it's click_event! Which is then loading one of the other controls. I have keypreview set to true on my main form, and I am catching some of the keys commands for shortcuts, but I don't have anything setup for the "enter" button. I am baffled as to how it could be triggering that toolstripbutton to click. The toolstrip isn't even the active control (that I know of...) at the time... my combobox dropdown is open. I would post code, but I don't have any code culprit that I could find... I know this isn't much to go on, but I'm completely at a loss and have no idea where to even start.

It's the same toolstrip button click event every time. Is there a property or something that I'm missing that may be causing this button to be triggered on enter?

I tried to remedy this by tying a button from each specific control to the mainforms acceptbutton property which seems to work fine if the dropdown is closed. But if the dropdown is open, it's still calling the toolstripbutton's click event...

Is it possible that the toolstrip for some reason has not lost focus when the dropdown is open?
 
The Default property on a button will cause the OnClick event to trigger when enter is pressed if the property is true
The Cancel property will cause the OnClick event to trigger when Escape is pressed if the property is true
 
Thanks for the response! I'm looking at the properties for the buttons (which are toolstripbuttons) and I don't see either one of those properties listed in the property window... Am I missing something? Should I try to set it to false programatically on application load? It's the same button that is getting clicked each time on the toolstrip, so I thought it had to be a property, but when I compare all of the buttons property lists side by side, I'm not seeing anything. So my next thought was maybe there was a property in the toolstrip itself (not the button) that was telling the app that this specific button was the default... but I'm not seeing anything there either.
 
Ok, so I just figured out what this issue was... a slight oversight on my behalf. I was letting the application catch the keypress event so that I could use shortcut keys to trigger application behavior, and a case statement was being used to evaluate the KeyAscii integer value... apparently both the CR (carriage return) & Ctrl+M return the same KeyAscii value (13). This is why my shortcut key was working, and the enter key was triggering the same event.

Anyone have any thoughts on how to differentiate between the CR and ctrl+m ?
 
Nevermind. I figured out how to handle. I used the keydown event and handled as such...

Code:
If e.Control Then
            Select Case e.KeyCode
                Case Keys.L
                    MsgBox("CTRL + T Pressed !")
                Case Keys.R
                    MsgBox("CTRL + B Pressed !")
                Case Keys.M
                    MsgBox("CTRL + A Pressed !")
                Case Keys.O
                    MsgBox("CTRL + T Pressed !")
                Case Keys.V
                    MsgBox("CTRL + T Pressed !")
                Case Else
            End Select
        ElseIf e.Alt Then
            Select Case e.KeyCode
                Case Keys.B
                    MsgBox("ALT + B Pressed !")
                Case Keys.A
                    MsgBox("ALT + A Pressed !")
                Case Keys.T
                    MsgBox("ALT + T Pressed !")
                Case Keys.S
                    MsgBox("ALT + S Pressed !")
                Case Else
            End Select
        End If

Thanks for looking at my post!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top