Im working on an app to control some stuff over bluetooth.
Currently I have a form with some buttons. On each button I want to trigger an event when the button is pressed down and fire a different event when the button is released.
Is this possible?
Not sure what the "bluetooth" info should tell me.
But in C# Winforms, yes that is possible. See the MouseDown and MouseUp Events: http://msdn.microsoft.com/en-us/library/system.windows.forms.button_events.aspx
(You may need to combine them with the keyboard events to capture them as well)
Related
I have a custom control which inherits from Control and I'm trying to trigger MouseLeftButtonDown using Touch on WPF platform.The event MouseLeftButtonDown does not fire while touch the window but its works fine when use mouse device. I have tried the related PreviewMouseLeftButtonDown event also nothing happens while touch the window.
Please suggest me the solution.
Regards,
Jeyasri M
Already in another post
WPF combining MouseDown and TouchDown to same event
Anyway have a look to this, maybe can help...
https://blogs.msdn.microsoft.com/llobo/2009/12/07/wpf-touch-basics/
https://blogs.msdn.microsoft.com/jaimer/2009/11/04/introduction-to-wpf-4-multitouch/
I wrote simple app that minimize to tray if Escape is pressed (use Form keypress event for this).
Also that app have label element for debug purpose. All work normal.
But when i try add some new element (like button or radio button) my keypress event did not start. Also if I add new label keypress still working.
I investigate that button keypress event start instead Form keypress event (Because it in permanent focused?). How to fix it property?
In the form properties, you will see the following:
Ensure that KeyPreview is set to True to allow the form itself to check the KeyPress event before the child controls.
So I'm making a simple program where I need to know if a button is pressed, and I need to know when a button is released after it's been released. I need to be able to complete an action when it's released
Winforms/WPF: MouseUp
WebForms: onkeyup
It's not really clear if you're working with webforms or winforms, but .NET provides event handlers for pretty much any event that could happen.
Here's a listing of the events Buttons handle.
The one you're looking for is 'Click'. This method will be fired whenever the user clicks on the button.
If you need to do something when the user pushes down on the mouse and again when he releases, Button isn't right for you. Many other objects implement the 'OnMouseDown' and 'OnMouseUp' events, though.
If you're talking about a winform and a keyboard press use the KeyUp event ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keyup.aspx ) If you're talking about a mouse click use MouseUp ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseup(v=vs.71).aspx ).
I have multiple buttons that are using a single command with a command parameter to act on their "down" event among all types of interactions (click, keypress, touch). Turns out this isn't enough for my application, and I must also know when the button is released. How do I do something similar for these buttons "up" event?
Look at the OnIsPressedChanged() method. You may have to derive a class from Button to be able to handle it.
Also, you may handle the MouseLeftButtonUp event, but it will fire only if the button is pressed by a mouse click. If you want to catch keyboard, you will have to process KeyUp events and determine if the the button was clicked as a result of that key (Space, Enter in some cases, a shortcut key, etc.)
Unfortuntely there's no special command for the UP-event.
But you can use EventToCommand behavior
I've found a combination of events are required to listen to:
PointerReleased, PointerCanceled, PointerCaptureLost should all be listened to in a touch environment for "up" events.
So how to begin.
I am asking when you make a game for example and you add a controlls how do I make the form's key events run when the focus isnt on the form but on some of the controlls and when i call this.Focus() or this.Select() it doesnt't happen anything, but if I use a empty form(with no controls) it works(the events respond).And when i have for example 2 buttons and call button1.focus() and press a key the button1's event handler responds (only it) adn then when i call button2.Focus() it responds for button2.How is focus distributed througt the controlls?
I know for muttons you have to click them once to put the focus on them automaticly and for textboxtes too,but when i click the form it doesnt move the focus on the form.
Im have almost no experience with Key events please explayn me how to use them and how they function understandly.
PS: sorry for the long questin
You can set the Form.KeyPreview to true to have the form react to key events.