DoDragDrop disables MouseMove Events - c#

After having started a Drag & Drop operation by DragDrop.DoDragDrop(...) no more MouseMove Events are fired. I even tried
AddHandler(Window.MouseMoveEvent, new MouseEventHandler(myControl_MouseMove), true);
where the last parameter means I even opt in for handled events. No chance, seems like the MouseMove Event is never fired at all! Any way to still get MouseMove Events while using Drag & Drop? I'd like to Drag & Drop a control, while dragging this control it shall follow the mouse pointer. Any idea how to do this in this case?

You need to handle the DragOver event.
EDIT: Try handling the GiveFeedback event on the control that you called DoDragDrop on; that might do what you're looking for.

What is the DragDrop.DoDragDrop construction? DoDragDrop is intended to be called in MouseDown/MouseMove method indeed, not in DragDrop. It is supposed to START handling the procedure, not to react for the drop (the desired effect of the drop you just implement directly in DragDrop). MouseMove never fires while already dragging, perhaps that's why it does not also fire with you, since you set the procedure. I think you handle this wrong way, here is one of examples http://msdn.microsoft.com/en-us/library/aa984430%28v=vs.71%29.aspx.

Related

Keydown event not firing in user control obj

I have a user control which is not declared in the designer. I have a button that I want to have create this user control when I click it - it should initialize the user control and insert it in the main UI.
However, it happens that the user control has a key press event on it, which is not firing.
Why does this happen?
I already tried to attach the event on the user control itself but it seems that it's not firing at all. Is there some kind of bug?
It is very hard to fix problems with code that you can't see, but in WPF, there are often reasons why Bubbling events like the KeyDown event don't fire. Occasionally certain controls may make use of these events and set them as handled internally, thereby stopping them from bubbling up any further.
The normal solution on these occasions is to use the related Tunneling events instead, which are raised before the Bubbling methods and not used internally by controls. So, while I can't guarantee that this will fix your problem, it is certainly worth trying to handle the UIElement.PreviewKeyUp event instead of the UIElement.KeyUp event.

How to separately handling MouseClick and MouseDoubleClick event on ChartControl

I'm implementing a module which needs to handle both MouseClick and MouseDoubleClick on a ChartControl of DevExpress. The version that I'm using is v12.2.
When I double click on that chart, both events are fired. I'd like (and I think that it must be) it just fires one event, in this case, MouseDoubleClick.
So, anyone know how to fix that problem?
What's I've tried:
Handle MouseClick or Click event and see MouseEventArgs#Clicks property. But it's always 1.
What's I'm using:
Declare a boolean variable to tell if MouseDoubleClick is fired. On MouseClick handling, just waiting for a moment, then do the codes if that variable does not turn on. I think this is a bad implementation.
You need a time machine to see the difference between the two. Inevitably a double-click starts with a single click, you always see the first click first.
You can get a time machine that sees the future by using a timer that delays the past. Set its interval to SystemInformation.DoubleClickTime + 16 and start it in the Click event, stop it in the DoubleClick event. If the Tick event fires then it was a single click.
That works, but do note that the delayed response to a single click is fairly annoying. Best not to annoy your user with a user interface like that.

Why does the DragLeave Event not use the DragEventHandler?

I only noticed this because I mistakenly tried to attach a DragEventHandler to a DragLeave event. I was surprised to see that the DragLeave Event was just as a general EventHandler. This is odd to me because both the DragDrop Event and the DragEnter Event use DragEventHandlers. Is there a reason or explanation for this?
Resources:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dragleave http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dragenter http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dragdrop
Yes. When handling DragEnter or DragDrop, we usually require or update additional information (such as the current drag effect, the active modifier keys, or the actual data involved). Therefore, the event argument passed to the handler has to provide access to that information.
On the other hand, there is not much we can (or should) do on DragLeave. We cannot cancel a leave. We cannot change the drag engine's behavior or the mouse pointer's shape because it's, well, a leave, the system's way of telling us thank you for your cooperation, we're done now, maybe we'll get in touch with you again in the future.

c# MouseUp is ignored while dragging an item to another panel

I try to drag an item from an ItemList to my TreeList. For that I wrote listView1_MouseDown, listView1_MouseMove, treeView1_MouseMove and treeView1_MouseUp functions. When I move the mouse within treeView1 borders, MouseMove event is handled as it was supposed to. But MouseUp doesn't fire. Am I doing something wrong?
Talking about Winfroms.
As far as I remember, MouseUp event is sent to the same control as MouseDown was sent to. So, in your case, your listView1 will receive MouseUp.
You might want to look into some other events, like DragDrop.

How to raise mouse events from code behind in different positions of screen?

How to raise mouse button events from code behind when we have only mouse position?
I need to raise mouse events from code behind in different positions of screen.
Umm.. quite simply no you can't.
Edit
Now that you've describe what it is you actually need to do (a useful techinque in getting your problems solved). Here is the solution:-
Use the AddHandler method to attach a handler for the MouseLeftButtonDown and the MouseLeftButtonUp.
myPanel.AddHandler(UIElement.MouseLeftButtonDown, MyButtonDown_Handler, true);
Note the final true parameter is the enabler here, it indicates that your handler should be called even if another element has indicated that the event has been handled.
Whilst you cannot add a handler for MouseMove in this way that is not a problem since MouseMove cannot be marked as handled anyway, so you just attach a handler to the Panel for MouseMove in the normal manner.

Categories

Resources