Hi everybody!
I'm writing a virtual keyboard, and i have a problem.As we know when press a key on real keyboard, control which focused will receive key event (defined by .Net)
for example:
you focus in a Multi line textbox, when you press key Enter. textbox will add 1 line and show cursor at that line.
. I think that textbox will receive Enter 's key code , after that textbox will perform 1 action with this Enter keycode.
so now i want to know that how to implement key event from buttton click event for a control.
Please help me! Thanks!!!
Kind regards.
Sugia
Kirtan PatelPosted Dec 18, 2009, 9:49 PM
private void Form1_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{
button1.PerformClick();
}
else if (e.KeyCode == Keys.B)
{
button2.PerformClick();
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button A");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Button B");
}
Kirtan PatelPosted Dec 19, 2009, 7:33 AM
if you want to send key to any control then you can do it with
SendKeys.Send("A");
if you want to send Enter Key then
SendKeys.Send("{Enter}");
that will send "A" to control ..
Su GiaPosted Dec 19, 2009, 7:17 AM
Have you ever wonder that why do you press number 1 on the real keyboard, at that time textbox input value is 1 ?
i think that every control have method to handle that event.
so i want to know that method to handle control so that i don't need writing code to handle data
Kirtan PatelPosted Dec 19, 2009, 6:32 AM
private void btnEnter_Click(object sender, EventArgs e)
{
textBox1.Text += "\n";
textBox1.Text += "\r";
textBox1.Focus();
textBox1.SelectionStart = textBox1.Text.Length;
}
private void btnA_Click(object sender, EventArgs e)
{
textBox1.Text += "a";
textBox1.Focus();
textBox1.SelectionStart = textBox1.Text.Length;
}
private void btnB_Click(object sender, EventArgs e)
{
textBox1.Text += "b";
textBox1.Focus();
textBox1.SelectionStart = textBox1.Text.Length;
}
Su GiaPosted Dec 18, 2009, 11:00 PM
Ex: you focus in a Multi line textbox, when you press key Enter. textbox will add 1 line and show cursor at that line.
.Textbox will receive Enter 's key code , after that textbox will perform 1 action with this Enter keycode.