How do I implement both clicking and dragging for the same control?
I have a control, and I want the 开发者_运维问答user to have the option to click on it, or drag it. Like files in windows explorer.
I know how to drag. I don’t know a simple way to have a click ‘fire’, since starting a drag on mousedown will prevent it.
Is there a simple way to do this?
Thanks.
I would recommend that you implement some type of visible drag handle that appears which would allow them to grab and move the control. Maybe if they hover over the control longer than 200 milliseconds or something like that.
you should search for examples on how to drag and move controls, I actually did it in Delphi looong ago (about 11 years ago) and it was all about mouse coordinates and flags to set on mouseDown and mouseUp.
I found something here: http://www.codeproject.com/KB/dialog/MoveYourControls.aspx could be source of inspiration for the solution in .NET
I've never done it but you could...
For the clicking, when the mousedown event fires, get the current location of the control. Then on mouseup, check if the current location is equal to the location from mousedown. If they are equal (or close to give some tolerance for accidental movement), then it was intended to be a click. If the difference is large, it was a drag and you can do whatever you need to do for that.
精彩评论