C#区分拖放和鼠标单击 [英] C# distinguish Drag drop and Mouse click

查看:216
本文介绍了C#区分拖放和鼠标单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许放置的表单,并且还需要捕获click事件。

I have a form which allows drop and also I need to capture the click event.

这里最棘手的部分是用户将对象拖放到 MouseClickEvent 也会被触发,因为他还单击了鼠标以释放该放置。

The tricky part here, is when the user drags and drop the object on the form, the MouseClickEvent also fired-because he also clicked the mouse to release the drop.

我该怎么办

预先感谢!

这是简短的还有更多的逻辑问题,所以我没有看到在这里放置代码的真正原因。

This is a short and more logic question so i didn't see a real reason to put pieces of code here..

谢谢!

推荐答案

添加一个全局布尔值,例如:

Add a global boolean, for instance:

private bool isDragAndDrop;

在加载表单时将其设置为false。触发dragAndDrop事件时,应设置 isDragAndDrop = true

Set it to false when loading the form. When the dragAndDrop event is fired you should set isDragAndDrop = true.

触发Click事件时,您检查 if(!isDragAndDrop)这将执行或不执行内部代码

When the Click event is fired you check if(!isDragAndDrop) This will or will not execute the code inside the click event based on the value on the isDragAndDrop -variable.

在离开点击事件之前,您设置的 isDragAndDrop = false

Before leaving the click event you the set isDragAndDrop = false

这篇关于C#区分拖放和鼠标单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆