+ 1
C#: How to get the element the mouse pointer is directly over
Hi everyone, I have a canvas where I drag and drop items. I want to put some restrictions on the drop event. For example, if item 1 have been dropped on the canvas, I want a situation where item 2 can only be drop on the canvas if the mouse pointer is directly on item 1. I have used the Mouse.DirectlyOver but it returns null. So, How can I get element directly the mouse pointer is directly over on drop event? Note: I am programming with C# Thanks!
6 Answers
+ 1
I am using WPF
+ 1
Thanks guys. This was helpful
0
Do you have a "dragenter" event in you control ?
What do you use Winforms or WPF ?
http://csharphelper.com/blog/2015/02/drag-and-drop-images-in-c/
In the "dragenter"-event
you can set the behaviour of the item being dragged.
quote :
// Allow a copy of an image.
private void picDropTarget_DragEnter(object sender,
DragEventArgs e)
{
// See if this is a copy and the data includes an image.
if (e.Data.GetDataPresent(DataFormats.Bitmap) &&
(e.AllowedEffect & DragDropEffects.Copy) != 0)
{
// Allow this.
e.Effect = DragDropEffects.Copy;
}
else
{
// Don't allow any other drop.
e.Effect = DragDropEffects.None;
}
}
0
wpf also has a dragenter event
https://wpf.2000things.com/tag/dragenter/
Does this help you ?
0
Another one. This one explains the mousedirectlyover.
https://wpf.2000things.com/2012/10/12/667-ismouseover-vs-ismousedirectlyover/
0
I do appreciatie of you mark a answer as best answer