开发者

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

how to do this:

when i'll press开发者_C百科 'G' on textbox in my form i'll see 'A' ?

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

thank's in advance


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


    void t_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == 'G')
            e.KeyChar = 'A';
    }


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';
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜