Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do this: i press 'G' on textbox and i'll see 'A'?

how to do this:

when i'll press 'G' on textbox in my form i'll see 'A' ?

in C# code (windows-CE or Windows-mobile)

thank's in advance

like image 741
Gold Avatar asked Nov 27 '25 16:11

Gold


2 Answers

    TextBox t = new TextBox();
    t.KeyPress += new KeyPressEventHandler(t_KeyPress);


    void t_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 'G')
            e.KeyChar = 'A';
    }
like image 133
Juan Nunez Avatar answered Nov 29 '25 05:11

Juan Nunez


I think you should handle the KeyPress event. Check if the key pressed is G, if yes, reject the input and put A in the textbox. Try this (The character will be appended to existing text:

    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        if (e.KeyChar == 'G')
        {
            // Stop the character from being entered into the control
            e.Handled = true;
            textBox1.Text += 'A';
        }
    }
like image 31
Sidharth Panwar Avatar answered Nov 29 '25 05:11

Sidharth Panwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!