I'm a beginner at C# and I'm making this calculator and it has multiple text boxes for different calculations. I've assigned calculator button numbers (0-9) for user input. I can get the number buttons to work for the various textboxes but they are all inputted at the same time. I want to make it so that if a certain textbox is selected, then the user can start using the buttons. Any ideas?
Thanks
You can implement the OnFocus event of the corresponding TextBox. In the method you should set the Enable flag of the Button instance to true where they were originally set to false.
Furthermore you need to keep track of which Textbox was selected last, and redirect output to that one if the user clicks a Button.
Related
I have a form with five textboxes. On a button click event I check if any of the textboxes are empty and if so, the empty textboxes have the background color set to LightPink.
I want to set the background color back to the default when the user enters the textbox to enter a value. I tried txtTextbox_MouseEnter to do that but the event is firing when other textboxes get focus with a mouse click. Oddly, the txtTextBox_MouseEnter event doesn't always fire when any textbox is clicked on - just sometimes - can't seem to determine a pattern in that behavior.
Why is this happening and what's the correct way to accomplish my goal?
I want the user to be able to type like = or whatever and then write an equation. Once they click off the box, I want the textbox to show the answer.
For example they could put =2+2 and it would display 4 when not selected.
I have no idea how to do this at all or even where to begin. I can get the textbox to calculate it somewhere else but not in the box itself where the equation is written or without having the user press a button.
What you're probably looking for is the LostFocus event. This event fires whenever a control loses focus (for example when a user tabs out of a text box). If you listen on this event for your text box, you can then call whatever processing code you want to handle any calculations required by the value of the text box and then set its value to the result of the calculation.
This is a concept question. I have a web form with 6 gridviews, below each gridview is a textbox. Each row of the gridview contains a question and 5 radio buttons. When a radio button is ticked or text is entered in the textbox it updates the database immediately with one caveat, the textbox is committed when the user presses the tab key, or refocuses curser outside the textbox, or clicks an unrelated button (basically when a postback or textchanged() event occurs).
The problem: There is a delay during postback when the text is committed to the database causing the user to think they can move to the next textbox only to have the curser return to the previous textbox. I added code to prevent the curser jumping but the delay is still an annoyance to users during testing. I added a confirmation message (label) to alert the user when it's ok to move on but when the confirmation message disappears at the next postback, usually when the user ticks the next radio button, the gridview shifts up and the user's curser is pointed to a different line of the grid. This is also annoying users.
Solutions? In my limited experience I have 2 alternatives maybe 3 (below). The reason I did not do either was because I wanted data to update the database as soon as it was typed or ticked. Since the radio buttons cause an immediate update I didn't want the users to inadvertently think the textboxes did too and forget to click a button to commit the text. Since entering text in the textboxes is optional, I don't have a way to validate if the user is done completing the form and remind them to click a button to commit their text input.
Put a button by each textbox to commit the text
Use one button to commit all textbox data when form is complete
Find a way to put a placeholder where the confirmation label is when its hidden so it doesn't shift on postback.
I'm starting to think one Submit button is the way to go and let the user think that is what saves the data? Simple.
At any rate is there a better way to achieve my goals of having input updated in database immediately without annoying delays (postbacks) and grid shifting at inopportune times?
In my case I changed the textbox AutoPostBack property to False and removed all code in the text_changed() event for all textboxes. I am committing the text when a Submit button is clicked. (The radio buttons still commit to db immediately when selected). In the end, I think users are conditioned to click a submit or save button when they finish filling out a form anyway.
I am working on a Nutrition Program that would allow a user to enter in the nutrition information for a item.
this is what my input form looks like every time a user clicks the plus button I need to create three new text boxes and a drop down box which would look like the above example.
This is what I am using right now but it only creates the textboxes for the first click. I need create the textboxes and combo boxes on every time the user clicks the add button.
Nvm,
I managed to do this myself using ViewStates it took alot of code but it works this is adding the controls on button click.
This is re-adding the controls on postback
And this is the results
I have a winform application with two textboxes. The textboxes are multilined and has 5 rows.
When the user enters more than 5 lines of text in the first textbox I want the text to continue in the second textbox. And if he/she deletes text from the first textbox I want the text to move back from the second to the first one...
I have tried to solve this in my code by checking how many rows the first textbox has and moved text between the two textboxes. But it doesnt work that well so I wonder if anyone got a better solution??
You could accomplish this by registering for the TextChanged events on the TextBox controls. Then in the event handler, manually inspect the Text property and set focus to the appropriate control. However, what you are describing sounds like it may lead to an inconsistent user experience.
From a UX standpoint I would suggest changing the approach. First of all do you really need to split the text in the UI, or could it be split afterward in the business layer? If you do need it split in the UI, you could have a single TextBox which allows the user to enter the full text, and below it have 2 read-only textbox's which display the 2 split segments as they type (you would also use the TextChanged event logic to do this as they type).
I hope this helps.
Have you tried checking the visible Characters in the text box? or text box character length?