当按钮仍然按下时如何转移鼠标操作的控制权
我有一系列 Panel
事件 - MouseDown
、 MouseMove
、 MouseUp
。我还在该 Panel
上为 Label
提供了事件处理程序。但在某些情况下,我希望 Label
的 MouseMove
处理程序将操作的控制权“转移”到 Panel
的处理程序。问题是该操作被“锁定”到Label
,因此诸如panel1.MouseMove += ...
之类的内容将无济于事,因为panel1.MouseMove在
。有没有办法“转移控制权”?MouseUp
之前不会引发
这是我所拥有的一个简单示例:(label1
位于 panel1
上)。
public Form1()
{
InitializeComponent();
label1.MouseDown += label1_MouseDown;
}
void label1_MouseDown(object sender, MouseEventArgs e)
{
panel1.MouseMove += panel1_MouseMove;
}
void panel1_MouseMove(object sender, MouseEventArgs e)
{
Text = "success";
}
在 MouseUp 之前,文本不会更改。
I have a series of events for a Panel
– MouseDown
, MouseMove
, MouseUp
. I also have event handlers for a Label
on that Panel
. But in certain cases I want the MouseMove
handler of the Label
to "transfer control" of the operation to the Panel
's handlers. Problem is that the action is "locked" to the Label
, so something like panel1.MouseMove += ...
won't help because the panel1.MouseMove
won't be raised until a MouseUp
. Is there any way to "transfer control" of the operation?
Here's a simple example of what I have: (label1
is on panel1
).
public Form1()
{
InitializeComponent();
label1.MouseDown += label1_MouseDown;
}
void label1_MouseDown(object sender, MouseEventArgs e)
{
panel1.MouseMove += panel1_MouseMove;
}
void panel1_MouseMove(object sender, MouseEventArgs e)
{
Text = "success";
}
The Text isn't changed until MouseUp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要时,您只需在
label1_MouseDown
中调用panel1_MouseMove
即可。You could simply call the
panel1_MouseMove
inlabel1_MouseDown
when needed.