gpt4 book ai didi

c# - 按下按钮时移动鼠标会引发什么事件?

转载 作者:行者123 更新时间:2023-11-30 19:32:48 25 4
gpt4 key购买 nike

我需要一个在 .NET Framework 的标准事件中不存在的事件。例如,鼠标左键按下时鼠标移动。

我还需要改变一些行为。例如,我有一些按钮,我想在按下鼠标左键时更改光标打开的每个按钮的背景图像,但是当我单击一个按钮并按住鼠标左键时,当我移动鼠标时其他按钮不会引发任何事件。

我该怎么办?如何创建新事件?我怎样才能改变行为?

感谢任何帮助。

最佳答案

您的问题是,当按钮上发生 MouseDown 事件时,该按钮“捕获”鼠标并且在释放按钮之前不会释放鼠标,这意味着其他按钮未接收到 MouseMove 事件。

有一些代码 from here这可能有帮助:

 // Assuming all buttons subscribe to this event:
private void buttons_MouseMove (object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
Control control = (Control) sender;
if (control.Capture)
{
control.Capture = false;
}
if (control.ClientRectangle.Contains (e.Location))
{
Control.BackgroundImage = ...;
}
}
}

关于c# - 按下按钮时移动鼠标会引发什么事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4827145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com