像在使用css的网页中,我们可以在鼠标输入或悬停中显示div,以同样的方式,我想在鼠标上显示一个面板输入一个按钮的事件,但我无法做到这一点。我正在尝试这样。如何在鼠标输入事件中动态显示面板?
private void btn2_MouseEnter(object sender, EventArgs e)
{
Button btn = (Button)sender;
btn.BackColor = System.Drawing.Color.MistyRose; //this is executed on mouse enter
Point locationOnForm = btn.FindForm().PointToClient(
btn.Parent.PointToScreen(btn.Location));
Panel pnl = new Panel();
Label lbl = new Label();
lbl.Text = "anything";
pnl.Controls.Add(lbl);
pnl.Location = new Point(locationOnForm.X, locationOnForm.Y);
pnl.Size = new Size(500, 500);
pnl.BackColor = Color.SkyBlue;
pnl.Visible = true;
pnl.Show();
}
我没有得到如何解决这个问题。我想知道
1)这是正确的方法还是有任何其他方式来做到这一点?
2)如果这是好的,那么我在这里做的错误是什么?
谢谢。