How to call a paint event from the mouse click event? - c#

I am having a mouse click event and i want to call a paint event of a picture box from this mouse click event, the paint event uses the event argument of it.

You can call the Invalidate method of the picture.

In case there is the method Invalidate which is specifically desing to do what you need to, and you don't want to follow that obvious way, the alternative is to
Send Message WM_PAINT to that control.

Related

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.

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.

Use right-click with Windows Forms Button

I am writing an app where the user should be able to alter the action of a button.
The user should right-click a button, and choose an option from a pop-up context menu. Once the choice has been made the button will perform a different action when the user uses a normal click.
I've already gotten the "Click" event working for a normal button click, however the "MouseClick" event handler isn't working correctly.
The "MouseClick" event gets activated on regular left-clicks, but never get's called for right-click.
Is there some default event handling being performed that is ignoring that right-click?
I'm sorry to say that this would be a serious UI blooper. Perhaps it would make more sense to add a small combobox next to the button.
Perhaps something like this?
http://www.codeproject.com/KB/buttons/SplitButton.aspx
If you want to display a context menu with actions to choose from it should be enough to assign a ContextMenuStrip to the ContextMenuStrip property. There is usually no need to manually handle the mouse events for that.
surely it would be better to implement it on the MouseDown event rather than the MouseUp event. i dont understand how this is much different from MouseClick event
edit: Just tried this and it works a treat :)
In Button (and certain other controls), the MouseClick event is only fired for the left button. Refer to MSDN.
If you want to know about the right button, respond to the MouseUp event--though as other posters have pointed out, this isn't a great UI idiom.
Use the Mouse UP event... test that Button.X and Button.Y are within the size of the button otherwise you have moved the mouse away from the button.
Terry G

Categories

Resources