How can I keep a Button control in the pressed state in a windows phone 7 app using C#? I want to have many different buttons on the screen, but when I press any of them I want it to stay pressed. Any ideas?
Also, once it is in its pressed state, is there a way to "depress" it manually?
Thanks
If the button properties are as follows:
foreground: white
background:black
Then in the pressing state its properties will be
foreground: black
background:white
If you change the properties of button in click event it can be seen as it is pressed. And making the IsEnabled property of button prevents it from firing the events on buttons.
Related
I'm new on C#, I made a button which makes appear another button and I want to remove the click event of this new one and change it into an enter(key) event.
Code1
Code2
When the button appears it only works when I click it but no when I press Enter.
As to your question, https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.enter?view=net-5.0
The enter event is for when keyboard or mouse enter the control (button in this case).
From the sounds of your question, you are wanting to click the button when the 'Enter' key is pressed.
If this is WinForms, then you might actually want a property on the parent form called 'AcceptButton' (https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.form.acceptbutton?view=net-5.0). This will make it so anytime the Enter key is hit (with the exception of controls such as a RichTextBox that accepts the return key) that button will be clicked (course you still need the button click event for the button).
Although you seem to be doing something weird in your example code image, so I'm not sure that's the correct solution for it. Instead, you need to look at maybe the Keyboard events, such as KeyPress (https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.keypress?view=net-5.0). There are several: KeyDown, KeyPress, KeyUp, and PreviewKeyDown.
Note these events require Keyboard focus on the control in question. So if add them to the button you are creating in your example code, then that button will need keyboard focus to receive the keyboard events.
Also, just FYI, if a button has keyboard focus, by default the SpaceBar will click that button for you, while the Enter key is generally reserved for clicking the Form's AcceptButton.
I'm trying to register a button press of the button F2 on the MC75a hand held terminal by Motorola/Zebra/Symbol. But it doesn't recognise the blue button press which is required to press F2. Any suggestions?
It depends on what is on your form. So if you have a windows form-project and a textbox is focused you could handle the keypress event of this control. If you have no focused controls, set your form to "keypreview = true". You can find this option in the settings of the form editor.
After enabling keypreview you can handle the keypress event from the form. This should work.
If you already enabled keypreview and it does not work, please make a test-form where you can see the keycodes which are send. There is a possibility to remap the keyboard of motorola devices.
I try to Designate the Accept Button property from my form to the click event of a label. If I would have used a button this wouldn't have been a problem but I have chosen to use a label for UI reasons.
Unfortunaly the Accept Button property only accept a button, so I have already tried to place a button on my form, make this button the acceptbutton and call the label_Click method when the button click_event is fired.
This worked like a charm but when I made the visibility property of my button false or made my button Hide() after the InitializeComponent() the Accept Button didn't worked anymore.
How Can the Accept Button property accept a label OR how can I visually hide a button without changing its visibility property?
Edit: a visualisation of what I tried to acomplish.
When the enter is pressed on the form (Accept Button property), I want to invoke the same method when the Play label is clicked.
To make the button "disappear" without hiding it you can change the border to 0, change the background color to the same color as the form and for FlatStyle property choose Flat. You could also use an image for the button background that is the same color as your form.
I need to have a toogle button in AppBar inside my WP7 app. But I see nothing except ApplicationBarIconButton.
Is it possible to have a toggle button in AppBar or make ApplicationBarIconButton to act as a toggle button?
no toggle button is not possible in the app bar. you can use application bar icon button and change the image depending upon user action
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?