I have a Windows Form in C# with 4 buttons with different states that I use as a menu.
What is the best way to use/implement the different button states.
Normal --> Mouse Enter, Mouse Leave and Mouse click. On click, that specific button should stay the clicked color and only change back to normal once a different button is clicked. Clicked color should also not change again on mouse enter or mouse leave. Should be flat buttons.
Thanks
change background of all buttons to default on click.
Then apply the Required backrgound to the button which triggered the click event by using the sender variable of the event
Related
There is a picture box and its onto a lable and when mouse enters the picture box's visibility is turned to false so that the label is shown the problem is I want to make the lable clickable but it's not working ..... I think the mouse enter event is blocking the click every thing is coded I didn't use the drag and drop thing.
If you double click on the label in Winform designer that should take you to the OnClick method for the label. There you can specify what you want to do when the user clicks on it. If you have done this and cant click or see the label. In designer place the label on top of the image, make the label not visible until the picture is hovered then click label.
I need to only fire the page click event if a normal page click happens, not when a user clicks somewhere on my page, then drags the mouse to a different location and lets go of the mouse button. Right now the page click event is fired when the user lets go of the mouse button regardless of where he first clicked or how long the mouse button was held down for. I cannot modify any code in the mouse drag, mouse down, or mouse up events unfortunately, so no solution involving these events will work for me.
I am building winform application without any form shown (opacity of form is 0 and ShowInTaskbar property is false). It is accessible only from tray Notify icon. When users clicks with left mouse button on it, the contextMenustrip menu will be show. Because I want to detect LEFT mouse button click I can't use ContextMenu Property of NotifyIcon.
I would like, that if users clicks whenever out of the menu, it should hide. I don't have any idea how I can do that...
If I have shown form, I could detect Deactivate form event and then hide my menu, but in described situation it looks harder.
1) Instead of setting opacity to 0 better set WindowState = FormWindowState.Minimized
2) You cant detect mouse clicks outside of your program as they are controlled by other programs or your OS, but handling Leave or MouseLeave event should help you
in my WP7 app using silverlight controls,
I have two buttons,
I want to make when I press a button, the other button seems like it's also being pressed (change of color to invert...etc)
something like the native keyboard on wp7 phones when the larger button appear above your thumb
I tried to give both of them the focus, but it's not possible
-Detailed Explanation-
usually, when you press a button, the button style changes according to the theme,
ex: if theme is dark, the button becomes white and the text becomes black. but if the theme is white, the button becomes black when clicked.
My aim is to mimic that behavior to a button when another button is pressed.
In the click event you could use
VisualStateManager.GoToState(Button1, "Pressed", true);
however to go back to the Normal state you would have to know when the click is over. LeftMouseButtonUp does not work because there is no mouse.
So you could set a timer and revert the state. Ugly but it works.
On a side note: I suspect the design you might want to use a different way of getting the result you need.
I haven't done much wp7 development but I believe the normal, active and pressed appearances are implemented as different states of the button and you can programatically set the state. This article should explain it in a bit more detail but the advantage of this approach over manually setting background colours is that it should automatically take advantages of any transitions configured between those states, as well as the black => white, or white => black theme related changes will be done for you too.
http://www.timmykokke.com/2010/11/using-visual-states-in-custom-controls-in-silverlight/
Update:
In the click handler of one set the background property of the other.
In pseudo-code:
Button button1
ToggleButton button2
Button1.MouseDown:
Set button2 pressed state to true
Button2.MouseUp:
Set button2 pressed state to false
try using MS Expression Blend to customize the behavior, details
In a mouseclick handler, is the correct way to know whether to show a context menu to check the event's Button property against MouseButtons.Right? If so, wouldn't there be a problem when a (probably left-handed) user tries to use your application with the mouse buttons reversed?
No it won't be a problem if mouse buttons are reversed.
Lets says I have reversed my mouse buttons, so when I press left mouse button, Windows will raise event for MouseButtons.Right and similarly MouseButtons.Left when right button is pressed.