我的Windows窗体代码有两个叠加的PictureBoxes:用户加载图像顶角的一个小X.我将分别称它们为DelImage和Image。像这样:
DelImage会在Visible = true
上显示(Image_MouseEnter
)并在Image_MouseLeave
上消失。现在,我希望DelImage在鼠标输入时也有自定义行为,但DelImage从不触发事件(MouseEnter
,MouseLeave
,Click
}。我已经尝试将它带到前面,但它已经在Image的前面了。
以下是一些代码:
private void picImage_MouseEnter(object sender, EventArgs e)
{
delImage.Visible = true;
}
private void picImage_MouseLeave(object sender, EventArgs e)
{
delImage.Visible = false;
}
private void picDelImage_MouseEnter(object sender, EventArgs e)
{
delImage.Visible = true;
this.Cursor = Cursors.Hand;
}
private void picDelImage_MouseLeave(object sender, EventArgs e)
{
this.Cursor = Cursors.Arrow;
}
private void picDelImage_Click(object sender, EventArgs e)
{
Panel currentPanel = this.tlpImages.Controls["pnlImage"] as Panel;
currentPanel.Visible = false;
}
使用此代码,永远不会到达picDelImage事件。我从未进入DelImage,显然是因为我从未离开过Image。我该怎么做才能使我的PictureBox具有预期的行为?