locked
how to change key press # with - RRS feed

  • Question

  • hi

    how to change the key press # with -

    in my C# Windows-EC program ?

    i need this:

    when i press # in my TextBox i need to see -

    thanks

    Tuesday, December 17, 2013 1:55 PM

Answers

  • One way is to handle the TextBox.KeyPress Event filter the characters.

    A sample implementation may look like this:

       using System;
       using System.Windows.Forms;
       using Microsoft.WindowsCE.Forms;
    
       public partial class Form1 : Form
       {
          public Form1 ()
          {
             InitializeComponent ();
    
             this.textBox1.KeyPress +=new KeyPressEventHandler(textBox1_KeyPress);
          }
    
          private void textBox1_KeyPress (object sender, KeyPressEventArgs e)
          {
             if (e.KeyChar == '#')
             {
                // Stop the character from being entered into the control.
                e.Handled = true;
    
                // create a new 'WM_CHAR' message and send it to the the TextBox control
                var msg = Message.Create (this.textBox1.Handle, 0x0102, (IntPtr)'-', IntPtr.Zero);
                MessageWindow.SendMessage (ref msg);
             }
          }
       }


    MVP Windows Embedded

    • Marked as answer by Eileen ni Tuesday, December 31, 2013 1:29 AM
    Wednesday, December 18, 2013 10:31 PM