0

我有 2 个 PictureBox ,名称:pictureBox1, pictureBox2 我怎样才能得到我点击它的图片框的名称?

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("clicked on: " + ??????);
    }
    private void pictureBox2_Click(object sender, EventArgs e)
    {
        MessageBox.Show("clicked on: " + ???????);
    }
4

2 回答 2

2

试试这个:

private void PictureBoxesClick(object sender, EventArgs e)
{
    if (sender is PictureBox)
    {
        MessageBox.Show("clicked on: " + ((PictureBox)sender).Name);
    }
}

使用此代码,您不需要 2 events,您可以为两者使用一个事件pictureboxes

于 2012-11-16T08:04:17.903 回答
0

试试这个

private void pictureBox1_Click(object sender, EventArgs e)
{
    String text;
    text=PictureBox1.Text;
    MessageBox.Show("Clicked on:"+text);
}
于 2015-12-02T16:10:56.500 回答