[英]Rectangle area over panel to catch mouse inputs
c#winforms here。 我需要在面板上繪制一個不可見的矩形區域並捕捉他的鼠標進入/離開事件。
我的情況(至於你可能有的其他一些建議):
我有一個媒體播放器(面板),在鼠標輸入事件我看到一個小導航菜單(它位於面板上)。 我想隱藏離開面板鼠標離開的導航菜單。 這可行,但不幸的是,進入導航菜單使其無形。 非常感謝。
在鼠標離開時,只需查看當前Cursor.Position
是否包含在矩形中。 例如,使用面板和標簽:
public Form1()
{
InitializeComponent();
panel1.MouseEnter += panel1_MouseEnter;
panel1.MouseLeave += common_MouseLeave;
label1.MouseLeave += common_MouseLeave;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
label1.Visible = true;
}
private void common_MouseLeave(object sender, EventArgs e)
{
Rectangle rc = panel1.RectangleToScreen(panel1.ClientRectangle);
if (!rc.Contains(Cursor.Position))
{
label1.Visible = false;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.