我想知道如何使用文本框进行PictureBox单击。
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
// I wanna a method to click on PictureBox1 here
}
}
答案 0 :(得分:1)
从另一个事件中调用事件是个坏主意。 (实际上,在代码中调用用户驱动的事件总是一个坏主意)。
如果要运行某些代码,请将其放在自己的方法中,并从每个事件中调用它。
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
MyPictureBoxCode();
}
}
private void PictureBox_Click(object sender, EventArgs e)
{
MyPictureBoxCode();
}
private void MyPictureBoxCode()
{
//common code
}
PictureBox Click
事件和Textbox2 Click
事件必须与您的designer.cs绑定。