我想知道如何使用文本框进行PictureBox单击。
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
// I wanna a method to click on PictureBox1 here
}
}发布于 2013-09-28 17:42:47
从另一个事件调用事件是个坏主意。(实际上,在代码中调用用户驱动的事件总是一个坏主意)。
如果要运行某些代码,请将其放入自己的方法中,并从每个事件调用它。
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绑定。
https://stackoverflow.com/questions/19069813
复制相似问题