Click and drag over buttons in WPF - c#

I have many buttons on my page. Every button has his own Click implementation.
When I click on some button and move the mouse to another button under that click (like drag), I want that click will fire on last button.
I have triend to do it with DragEnter and DragOver events but nothing happens.
<Button Click="btn1_click" DragOver="btn1_click"/>

Related

C# Forms - Only the first of what should be two consecutive events triggers

I have a TextBox with a "Leave" event and a Button with a "Click" event. There is no code in either event handler.
If I place the cursor in the TextBox then leave it by clicking any other item, the "Leave" event triggers.
If I place the cursor anywhere except in the TextBox and click the Button, the "Click" event triggers.
However, if I click the Button with the cursor inside the TextBox, only the "Leave" event triggers.
How can I get both events to trigger in the third scenario?

Handle button which has drill-down menu

So i have a UI that when you right click on a button, it opens a screen with 3 other buttons on it. How do i get the event system to not override the last button clicked (being what i right clicked to open the screen) when i click down on the button that is opened. The only way i can think to do it is to store the button that was right clicked in another variable. I was wondering if there was a way to prevent the event system from overriding the last button pressed. So that my code will run off what was right clicked and not the button that was clicked.

Image MoueUp event vs Button Click event

I have seen that many users have asked how to make a clickable image in WPF.
Image has Mouseup event. It works like Button click event as I understand.
Is there any difference in Image Mouseup event and Button click event?
Mouseup event, user can click somewhere else on the screen and hold down the click button and move the pointer to Mouseup element, and then release the mouse.
Click event requires both the mousedown and mouseup event to happen.
The MouseUp can happen in a different control from MouseDown.
A Button can also be bound to a Command and thus separating your logic from the UI.

Handling PointerEntered and PointerReleased but passing Click/Tap to parent element

I have a Grid and inside the grid, I have Buttons. I need PointerEntered and PointerReleased events as I need to track which buttons are hovered. The problem is that, I need my Grid to handle the click events. Even though I don't have a click/tap/press handler for the button, my button captures the click and doesn't bubble it up to its parent (Grid). If I disable the button by settin IsEnabled to false, the click event is bubbled up to the Grid correctly, but then PointerEntered and PointerReleased events aren't fired, which I need to handle on the button. How can I handle enter/release events on the button and at the same time, pass the click event to its parent? I need my Grid to go onto "clicked" state as I also listen for the PointerReleased event on it. If click doesn't fire, released doesn't fire even if I do release the mouse button when on the Grid.
Thanks,
Can.
Try using AddHandler to attach a click event to grid and see if it works for you.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.addhandler.aspx
Remember to remove the event using RemoveHandler when done.

How to change Event properties & create new events in C# .NET

I'm using NotifyIcon (System tray icon) in my WinForms application. I also have a ContextMenuStrip assigned to it. When user right clicks on NotifyIcon this ContextMenuStrip pops up.
These are the only events that NotifyIcon has.
Click
DoubleClick
MouseClick
MouseDoubleClick
MouseDown
MouseMove
MouseUp
This contextMenuStrip items (ToolStripMenuItem) are dynamically generated. I mean there are few default items like 'About','Exit','Help' etc.. but other items are dynamically generated and inserted into this menu when user right clicks on it. I'm generating items and inserting into contextMenuStrip in Click event handler
Now, I've two problems:
Problem is for an instant its showing the default menustrip and then my Click event handler executes and new update menu pops up. How can I avoid this? I don't want to see the default menu at all. In other words I need to override the default behavior.
Other problem is since I'm handling the Click event (because I didn't find RightClick event) the left button click also is handled by the same handler. I want to do different things (like show application windows) on left click and show dynamically generated contextMenuStrip on right click. How to acheive this?
Why are there two different events like Click & MouseClick? What else would we click with? Aren't these two interdependent. I mean when ever there is a MouseClick there is also a Click.
If you can point me to some examples. That would be great!
Item #1) The ContextMenuStrip has events that allows you to handle any dynamic creation of menu items before the menu is displayed. See the Opening and Opened events.
Item #2) Use the MouseEventArgs parameter to inspect the mouse-state when event was raised.
Item #3) Depending on the control, Click and MouseClick can be different. Take buttons for instance. When a button has focus, the "Click" event is raised when the user presses the Space or Enter key. In most cases, a MouseClick generates a Click event.
I'm the OP. I guess I've achieved it.
notifyIcon.MouseDown += new MouseEventHandler(notifyIcon_MouseDown);
and
static void notifyIcon_MouseDown(object sender, MouseEventArgs e)
{
NotifyIcon notifyIcon = sender as NotifyIcon;
if (e.Button == MouseButtons.Left)
{
MessageBox.Show("Left Button Clicked"); // & do what ever you want
}
else
{
updateMenuItems(notifyIcon.ContextMenuStrip);
}
}

Categories

Resources