Select to view content in your preferred language

Capture [Enter] Keystroke from MaskedTextbox on UserControl

1117
5
04-30-2010 10:08 AM
JamesCrandall
MVP Alum
As the title suggests, I implemented a UserControl that contains button and Masked Textbox controls that is added to ArcMap as a ToolBar.  All works fine except for an issue that would not be a problem IF the Masked Textbox was on a regular WindowsForm.

The problem is that I cannot seem to capture the key stroke of the [Enter] key of the KeyDown event of the Masked Textbox.  I have no problem getting anyother key, but the KeyDown event doesn't even pickup the [Enter] key.  As I mentioned, if this control was on a regular windows form it wouldn't be a problem, but this is a control placed on a UserControl with no windows forms in sight.

After the user types into the Masked Textbox and hits the [Enter] key, I'd like to 'do something.

Any suggestions?
0 Kudos
5 Replies
JamesCrandall
MVP Alum
Bump TTT

Anyone have any suggestions?  Even google searches have produced very limited results on resolving this issue.  I have found one thing, "esriKeyIntercept", but I have no idea where to implement this in regards to my UserControl. 

Again, I am trying to capture the [Enter] Keystroke after the user types into a MaskedTextbox located on a UserControl that is added to ArcMap.  The UserControl acts as a Toolbar on the menu area, and all items do work as expected. I just cannot seem to capture any time the [Enter]/Return key is hit!

Any input on this is greatly appreciated as I've run out of places to look for answers.

Thanks

j
0 Kudos
JamesCrandall
MVP Alum
ttt

Anyone have comments regarding this?

Thanks!
0 Kudos
KirkKuykendall
Deactivated User
Using Spy++, find out if its the parent, grandparent, or greatgrandparent ... that is getting the Enter key press message.

Once you know that, write a class that uses IToolControl.hwnd to find the ancestor and subclass it to capture the  message before it has a chance to block it.

http://support.microsoft.com/kb/815775
0 Kudos
JamesCrandall
MVP Alum
Using Spy++, find out if its the parent, grandparent, or greatgrandparent ... that is getting the Enter key press message.

Once you know that, write a class that uses IToolControl.hwnd to find the ancestor and subclass it to capture the  message before it has a chance to block it.

http://support.microsoft.com/kb/815775


Thanks for the tip, Kirk...

I'll continue down this route as this is the only info I've been able to acquire regarding this!

Thank You!!!
0 Kudos
JamesCrandall
MVP Alum
Just a follow up with the solution to this issue...

Kirk, thanks again for the comments.  Before I had set off to pursue the info you provided, I was thinking this had to be a much more basic problem that has a very simple solution.  It does.  So, I tried one other thing (not sure why I missed it before):

The KeyUp Event of the Masked TextBox control.

For whatever reason, the KeyPress and KeyDown events do not recognize the Return/Enter key --- they DO fire, but just not for THAT particular key stroke.  So this issue is resolved quite simply by this:

Private Sub txtPIDSearch_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPIDSearch.KeyUp
        Try
            If e.KeyValue = Keys.Enter Then
               'do something
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub



Thanks again for your input, I appreciate it.

Take Care,

j


Thanks for the tip, Kirk...

I'll continue down this route as this is the only info I've been able to acquire regarding this!

Thank You!!!
0 Kudos