I have a following form in WinForms as a prototype for a game:
GestureControl is a transparent Control that handles its MouseDown and MouseUp events to allow for swiping gestures. Then there are SquareControls (game pieces) that should be clickable as well.
I'm not sure how to arrange these controls so both
SquareControl will receive Click event
GestureControl will receive MouseDown and MouseUp events
I know I could add a Click Gesture to my GestureControl (when the distance between mouse down and mouse up is not far away), pass it to parent and invoke the same event handler as if the corresponding SquareControl was clicked, but this seems hackish.
Related
I use ScrollViewer. When I scroll the page with the mouse wheel, everything works fine and the ScrollChanged event cause after each scroll. But when I scroll through the contents of the panel by pressing and holding the scroll bar, then ScrollChanged cause only when I release the mouse button. How can I fix this and make it always update the content.
From Pro WPF 4.5 in C#:
Finally, the ButtonBase class adds a ClickMode property, which determines when a button fires its Click event in response to mouse actions. The default value is ClickMode.Release, which means the Click event fires when the mouse is clicked and released. However, you can also choose to fire the Click event when the mouse button is first pressed (ClickMode.Press) or, oddly enough, whenever the mouse moves over the button and pauses there (ClickMode.Hover).
I have a UWP app in which I have several buttons. Once the app starts to run, I set the focus in my code to the first button using a code like this:
firstButton.Focus(FocusState.Programmatic);
After this point, what I am interested in is that once the user use the mouse wheel, the UWP app automatically scroll to second, third, fourth, ... button(exactly like when we use tab key on keyboard to move between buttons).
However, when I use mouse wheel, nothing happens in the app.
I should also say that in firstbutton xaml, I use pointerwheelchanged event listener to change the focus to second button. However, this event handler does not work with mouse wheel UNTIL I MOVE THE MOUSE CURSOR INSIDE THE AREA OF FIRST BUTTON. What I am interested in is that this scrolling using mouse wheel becomes automatic exactly like the tab key of keyboard.
Any suggestions?
Place the event on the container control (like the Grid). If it's a control that already processes the event, use the AddHandler method with handledEventsToo set to true.
I have a form with the panel, which will have some checkboxes for options. I made panel slide in to the form when mouse hovers the edge of it (edge of panel). I made it hide (slide back) when mouse leaves the panel. The problem is that when I point a checkbox in this panel a mouseleave event occures and panel slides back so I cannot check checkbox. Is there any way to prevent mouseleave event when mouse is still over the panel and some checkboxes in it? My idea for know is to make a condition based on mouse pointer position in mouseleave event, but I hope that there is a way to make app treat a checkbox as a part of panel. Did not put any food since it is not problem of it. But can post if needed.
What happens here is that the mouseleave event of the checkbox triggers mouseleave event of the panel due to the event bubbling. You can read more about event bubbling here.
To prevent the event bubbling, attach mouseleave event on the checkboxes and call event.stopPropagation().
Sample code with jQuery:
$("checkboxes_selector").on("mouseleave", function(event){
event.stopPropagation();
});
I am writing an event for a textBox_Touch_up. And I want if user Touch Up on the text box then fire this event but if user dragged his finger somewhere out of the textbox and then touch up then this event should not be called. Is there any other event with which I can do it or I Have to play with it ?
The touch_up Event does not provide similar functionality for Textboxes because Textboxes contain text. So I used a flat button and it works for me as it does not fire the event when i drag my finger out of it.
I have a Canvas with event handlers for MouseMove & MouseLeftButtonUp. Inside the canvas I have placed image icons. I want to rotate the icons using drag events like the iPhone. How can I capture the click event on an image?
To determine if you are dragging either:
Record when a mousedown event is fired and then clear that record when mouseup fires. Check this record in the mousemove event.
Check e.LeftButton == MouseButtonState.Pressed in your mousemove event.