English 中文(简体)
compact framework 2.0 detecting enter key in a textbox
原标题:

I am developing a small app for a Motorola 9090-G using .net compact framework 2.0.

My problem is that I can t seem to detect an enter keypress in a textbox. How do you detect an enter keypress in a textbox?

None of the 3 detection methods seems to work. Interestingly, it DOES work in the ppc emulator. It does not work on my actual hardware however.

private void tbxQTY_KeyDown(object sender, KeyEventArgs e)
{    
  if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter || e.KeyCode == Keys.Decimal)
  {
    QTYEntered();
    e.Handled = true;
  }

  if (e.KeyData == Keys.Enter || e.KeyData == Keys.Return)
  { do something }


  if (e.KeyValue == (char)13)
  { QTYEntered(); MessageBox.Show("test"); e.Handled = true; }
}
最佳回答

For me the answer was to use the KeyPress event, not KeyDown:

    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 13)
        {
            // Enter
        }
    }
问题回答

The device may not be handling the button press in a way that is accessible to you.

Have you checked that the event is actually being triggered?

If not, you may want to look at other events or possibly capturing HardwareButton presses instead.

OEMs configure their keys differently sometimes. The trick is to create an app that just handles the key up and key down events and then query the values you get when pressing the relevant keys. YOU MAY BE SUPRISED at the results.

I had an Intermec unit once. Enter was correctly enter, however the ACTION key was Enter followed by F23 about 10 ms later. God... that was hard to code around to make that key useful (i.e. do something that wasn t the same as the enter key). The solution included a function called:

public bool IsReallyEnter(KeyEventArgs e);

KeyPress is an okay workaround, your issue is that it will fire multiple times if they hold the keydown.

This is how I do it now to navigate between fields and on the "last" field, I call my save function. I do not miss a key:

Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        Select Case e.KeyCode
            Case Keys.Enter
                ComboBox2.Focus()
        End Select
    End Sub




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签