+ 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!

15th Oct 2018, 7:42 PM
John Ansa
John Ansa - avatar
6 Respuestas
+ 1
I am using WPF
16th Oct 2018, 8:17 AM
John Ansa
John Ansa - avatar
+ 1
Thanks guys. This was helpful
17th Oct 2018, 5:03 PM
John Ansa
John Ansa - avatar
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; } }
15th Oct 2018, 9:36 PM
sneeze
sneeze - avatar
0
wpf also has a dragenter event https://wpf.2000things.com/tag/dragenter/ Does this help you ?
16th Oct 2018, 10:20 AM
sneeze
sneeze - avatar
0
Another one. This one explains the mousedirectlyover. https://wpf.2000things.com/2012/10/12/667-ismouseover-vs-ismousedirectlyover/
16th Oct 2018, 7:30 PM
sneeze
sneeze - avatar
0
I do appreciatie of you mark a answer as best answer
17th Oct 2018, 5:08 PM
sneeze
sneeze - avatar