How To Enter A TextBox On Click - c#

Im trying to create a basic example sign up page.
I want the mouse pointer to enter the textbox only on click however it seems to enter the first textbox by default. What is the process to change this?

You could use the opacity and sets it to 0 together with the IsEnabled attribute which I would set to false.
Then you put in your click event this simple code.
textbox.Opacity="1";
textbox.IsEnabled="true";
I hope this helps you.

Related

Enter focus on a button while still being able to type in a textbox

Is there a way to have both a textbox and a button in focus? I know that I can use textbox1.focus to focus the textbox, and same with the button, but is there a way to be able to have enter focus on the button, while still typing in the textbox?
I know that I can just use the key-press event to capture the enter key, but I'm wondering if I can have enter focus on the button.
Just curious to know if this is possible, a simple yes or no is all that's needed. Thanks!
Only one element can have input focus at a time. You can't specify the focus for just one key.
So basically, no, you can't do that.
You don't need to have focus on both controls to get the behavior (I assume) you want. Just set the parent form's or dialog's AcceptButton property to the button you are talking about; its Click event should be triggered when you press the ENTER key even while the TextBox has focus.
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx
To make the answer complete (edit):
As stated above in my comment to your question (and likewise by other contributors): only one control can have focus at any given time. So, the answer to your original question is:
No, there is no way.
As Bradley said, you can't.
But for your aim, there is a shortcut, called Form.keypreview property, which let's you evaluate keys before they reach the textbox or other controls.

c# WinForms TextBox_Leave

I have a small problem. I have a TextBox myTxt. I set the myTxt_Leave event to check the database if input value already exists. If value exists, I display a MessageBox and set myTxt.Focus(). That wont let user to leave this TextBox, until another value (which does not exist in the database) is input.
But here is the catch...I would like to allow user to click on Cancel button on the form even if the value does not change. Is that possible?
Hope someone understands what I wanted to tell.
Thank you for any help.
EDIT:
I decided to change the interface a little. I put red label under the textbox "Value already exists" and disabled the Submit button until the value is correct.
But still, I'm curious if solution for my previous problem is possible?
Instead of binding the event to the Leave interaction, just Highlight the box in red and disable the submit. When the when the error is resolved or the action is cancelled, clear the red / disabled submit button.

C# Check box, only check the box not the text

Okay i swear i looked for this on google before posting.
I tried:
C# check box active area
C# check box check box not text
and a few others.
But i have a check box on top of a button. I want to be able to click the button even when the mouse is over top the check box text area. I want the use to only be able to click the actual box. But when the mouse is over the check box's text, it should click the button.
Thanks all!
I'm assuming this is in WPF / XAML.
Simply add the checkbox to the button without text. Add the text to the button not the checkbox.
That said, I cannot for the world think why this would be a pleasant user experience and would suggest trying to use a different means of getting the information.
So instead of having the checkboxes over top the button, i just created a seperate window that will show with the three options to choose from upon clicking that button.
But i still think it would be cool/neat to have them on top of the button.

Cancel checkbox checking, when input not corret

(Using WPF application)
This is the situation:
There are 3 user input fields. 1 for hours, 1 for minutes and 1 for seconds.
Behind it is a checkbox for "divide time by half" that does nothing more than devide the timespan created by the user input by half.
But when the checkbox gets checked, i first make a check in the code if the user had put in any numbers in the fields: hours/minutes/seconds.
If all are 0, a messagebox pops up telling the user he needs to put in something.
But at this point, i want to "cancel" the checking of the checkbox.
Should i use something as e.Cancel or something ?
Or should i set the IsChecked back to false together with the messagebox ?
Im wondering wat the correct way of dealing with this is.
I think your approach is wrong.
The checkbox should enable only when there is valid input.
You could set a LostFocus event on your textboxes and inside that event check the all the input values.
If input is right then enable the checkbox else disable it. No need to cancel the checkmark
The action of clicking the checkbox has a two step behaviour:
Validating the time
Dividing it by half
If you want to maintain those two step in an unique operation the action of checking the checkbox in fact triggers the event, the validation step is performed, then you uncheck it. I think that from this perspective it is more correct to set checkbox.IsChecked to false.
As pointed out by Steve I would separate the validation step from the operation. Disable the checkbox when the input is not valid putting a check function on the TextChanged event of the textboxes. If everything is fine you can enable the CheckBox. If not disable it and uncheck it if it is checked.

C# Auto Clearing Winform Textbox

I have a user that want to be able to select a textbox and have the current text selected so that he doesn't have to highlight it all in order to change the contents.
The contents need to be handle when enter is pushed. That part I think I have figured out but any suggestions would be welcome.
The part I need help with is that once enter has been pushed, any entry into the textbox should clear the contents again.
Edit: The textbox controls an piece of RF hardware. What the user wants to be able to do is enter a setting and press enter. The setting is sent to the hardware. Without doing anything else the user wants to be able to type in a new setting and press enter again.
Hook into the KeyPress event on the TextBox, and when it encounters the Enter key, run your hardware setting code, and then highlight the full text of the textbox again (see below) - Windows will take care of clearing the text with the next keystroke for you.
TextBox1.Select(0, TextBox1.Text.Length);
OK, are you sure that is wise? I am picturing two scenarios here:
There is a default button on the form, which is "clicked" when enter is pushed".
There is no default button, and you want the user to have to press enter, regardless.
Both of these raise the same questions:
Is there any validation that is taking place on the text?
Why not create a user control to encapsulate this logic?
If you know the enter button is being pushed and consumed fine, how are you having problems with TextBoxName.Text = string.Empty ?
Also, as a polite note, can you please try and break up your question a bit? One big block is a bit of a pain to read..

Categories

Resources