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
Related
I've created a little test scene where I want to use the PressableRoundButton prefabs to additively load a scene when pressed. I've hooked up the button to call into a script and pass the name of the scene I want to load, this code is verified to work with a debug keyboard shortcut so I know that part is good. What doesn't seem to work is the button event itself. Perhaps I've gone and done something really stupid, but I stupidly can't figure out what I've done wrong.
I'm using the DefaultMixedRealityToolkitConfigurationProfile which may or may not be the problem but I'm a little unsure how to diagnose that. I kind of figured the default one would be the safest bet. I can see the button visually press down when I click on it using the WMR controller so all the mechanics behind the button are working in terms of having it push down and all when I hit the trigger while pointing at it
Button Events list
Thank you for sharing an image of your setup! Try calling your code not in the PressableButton component, but on the Interactable component's OnClick handler (you need to expand the "Events" dropdown in Interactable.
The PressableButton component actually will only raise the button pressed, etc. events when you are directly poking a button with near interaction. For pressing the button at a distance, use the OnClick event handler in Interactable.
Have a look at the picture here to see where the OnClick handler lives.
Note that OnClick will only fire on pointer unpressed, and will also (currently) not fire if you stay pressed for too long. If you'd like to instead run the code when you press down, you can instead handle the OnPress event.
Have a look here for that example.
Note that by default Interactables only handle an OnClick event -- you add more event handlers by adding "Event Receivers" by clicking the "Add Event" button. You can then pick the receiver type. In the case of the round button prefab, there is already a InteractableOnPressReceiver set up for you that exposes the OnPress and OnRelease events.
The way to think about buttons in MRTK is:
Interactable is actually a 'button' that can be interacted with both nearby and at a distance. It exposes many different event handlers, and has lots of visual options. It's called "Interactable" and not "Button" mostly for historical reasons (it was that way, people started using it, now changing it would break many people).
PressableButton is a more complex touch-only button that actually moves in with your finger. Pressable button actually talks to Interactable, setting things like its pressed state, so that folks can listen just to Interactable if they want to work both near and far.
In most cases, add your event handlers to Interactable, not pressable button. Pressable button is for touch only.
I want to be able to hold down a button (i.e. MouseLeftButtonDown) and have it's event repeat fire.
I code Mouse.Capture(button) in the MouseLeftButtonDown event and Mouse.Capture(null) in MouseLeftButtonUp event.
If I hold the mouse button down, the MouseLeftButtonDown only fires once. I can see this not by setting a breakpoint but by using Console.Writeline().
I had this very code working at some point. Then I refactored and put the mouse events in an Interface. Everything still works except this repeat action now!
Update - More information:
Here is the before call which was in a specific class:
Mouse.Capture(sender as MenuGelButton)
MenuGelButton is a xaml creation of ellipses and text to make a cool button.
Since adding the interface (which is common code for several xaml creations all of which inherit the interface), here is the current call from within the interface:
Mouse.Capture(sender as UIElement)
Update of Update:
A mouse click event is not designed to auto repeat fire. A keyboard event is. I had this working (and it continues to work) on a keyboard event not the mouse event. Sorry for the confusion...
I believe you are looking for Microsoft's RepeatButton. You can use it in XAML just like you would use a Button, and it fires a click event multiple times.
From their documentation:
A RepeatButton is a button that raises Click events repeatedly from the time it is pressed until it is released. Set the Delay property to specify the time that the RepeatButton waits after it is pressed before it starts repeating the click action. Set the Interval property to specify the time between repetitions of the click action. Times for both properties are specified in milliseconds.
Try doing something like this:
mouse button --> fires event
in the event, set a timer of your liking (how many times per second would you like the action to happen?)
in a loop, every time timer fires, check to see if mouse button is still "down". If yes, fire. If not, don't fire.
you'll probably want to add another event of mouse button up, that will stop the timer, so it won't fire anymore (or bind to a bool that will let you know if you want to fire ... up to you ..)
Hope it helps.
Simply put, I want to be able to get the event of a mouseclick (specifically MiddleButton) when a user clicks the button - not after it's been released.
I think I've done it once before, but I've forgotten.
This is to be able to navigate a 3D view when the user clicks the button, in an XNA project.
Are there any similiar ways to register HotKeys but for the Mouse?
Isn't that just the MouseDown event?
I have written a custom control in C# (inherited from Forms.Control) and it seems to working fine, but if you press the button fast enough a problem occurs: only every other click will call the click event handler. This doesn't happen if you don't press it fast (less than once a second). The mouseUp and mouseDown handlers always get called no matter how fast you click the button.
Of course doesn't happen with the canned winform button.
I cannot use the canned button because I'm writing an application for the .net compact framework, so I need a custom control in order to make the UI more presentable. Also, I tested out my code on the full version of the .net framework, and I still have the same problem.
Any help would be greatly appreciated. Thank you!
If you are clicking rapidly enough, you are getting into DoubleClick territory.
According to above MSDN Page the order of events are:
The following series of events is raised by the control when such a user action takes place:
MouseDown event.
Click event.
MouseClick event.
MouseUp event.
MouseDown event.
DoubleClick event.
MouseDoubleClick event.
MouseUp event
If you will notice there is only one Click event per DoubleClick
For a way to disable it try looking at this MSDN Page discussing ControlStyles.
From above link:
StandardClick -- If true, the control implements the standard Click behavior.
StandardDoubleClick -- If true, the control implements the standard DoubleClick behavior. This style is ignored if the StandardClick bit is not set to true.
So try this in your controls constructor or load event:
this.SetStyle(ControlStyles.StandardClick, true );
this.SetStyle(ControlStyles.StandardDoubleClick, false);
Since SetStyle does not appear to be in the Compact Framework you could add a DoublClick Event and have it trigger the Click event Programmically like this.
YourClickEvent(sender, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left,1,0,0,0));
When you click your control fast enough, it calls double click rather than click.
So, you should do something like this in your click function:
{
control.Enabled = false;
......
control.Enabled = true;
}
I am using UltraComboEditior of Infragistics Conrtrols in C# winform application, I want to show a messageBox when UltroComboEditior got focues by MouseClick or KeyBoard Tab button, how can I do it? Any suggestions ? I tried BeforeDropDown but it is called only when we click on arrow button to show drop down list but I am using only drop down with auto complete option set to be true.
UltraComboEditor control has "Enter" event which fires when the control becomes the active control of the form, and this event will fire in both situations - when the control got focus by using your Tab key, and when you are using your mouse.
I hope that this will help you to achieve your goal.
Doesn't it inherit the OnGotFocus event which you can subscribe to?