Greetings,
I have a form where employees enter comments in a multiline textbox with a limit of 4000 characters. I have the rows set to 8 (obviously an arbitrary number).
When a supervisor looks at the comments the textbox is disabled so the employee comments cannot be modified.
The problem is when the data extends below row 8. Since the textbox is disabled the scrollbar cannot be moved and the supervisor cannot see all the comments. If I hide the textbox and databind to a label for the supervisor none of the line breaks are maintained and a well written paragraph turns into the biggest run on sentence ever…
Is there a way to enable the scroll bar leaving the text disabled?
Is there a way to preserve the structure of the entry in the label?
Instead of disabling the textbox you should set the ReadOnly property to True. This keeps the scrollbars functional but doesn't allow modification of the textbox.
txtComments.ReadOnly = true;
In supervisor mode, don't put the text into a textbox, put it in a label as you mentioned, with '.Replace("\n", "<br>")' in your code.
Alternatively, show the textbox without disabling it, and just disable the 'save' button. Put a note on the page saying that, "changes made here are not persistent" or something to that effect.
Make the text box read only, and set the fore color to the same shade of grey used in disabled text boxes.
<asp:TextBox ForeColor="#AFAFAF" ReadOnly="true" />
Put the text in a PRE tag, and apply overflow:scroll to it.
Make sure to escape the text using Server.HtmlEncode first.
Related
I´m trying to set textbox visible = false to avoid user from write on it manually but I still need it to write on it by using a bar code scanner, so I need it to get focused before use the scanner, what would be the better way to do it?
Your best option would be to simply validate that what's entered into the textbox is indeed a bar code. What happens when the scanner breaks down and the user still needs to enter a bar code? Limit it to numbers only.
If that's not an option and you find the scanner doesn't work with hidden or disabled textboxes, then set TabStop = false and Multiline = true, and try setting the text box size to 0x0. Or at least really tiny and make it the same colour as the background. In that case you'd want a label or something to then display the bar code or product info so the user knows the scanning worked.
Another possibility may be to set KeyPreview = true on your form. Then you can handle anything that looks like a bar code in the form's KeyPress event, no matter which control is focused. If numbers start coming in, capture them, and if it turns out not to be a bar code, just forward them to the focused control.
just simply set textbox property size to (0,0) with textbox visible = true
From the question, you want to achieve two things.
Make the textbox invisible before Scanning.
Lock the user from editing the textbox after bar code scanning.
Solution
Set the textbox visibility property to false before Scanning so that it does appear on the screen whatsoever.
Have an event handler after finishing scanning or at the end of your scanning method/function, change the Property of the textbox called Disabled to true.
Hope this helps.
If the purpose of hiding textbox is to not-allow user from editing it, then
you may set the ReadOnly property of texbox to true, then call the .Focus() method
before scanning the barcode. In my experience, after having installed the barcode
reader driver, softwares from accompanying CD, all you have to do is scan the
barcode and it will populate with the barcode-value in human readable format,
on any control in an application that can take user-input. I suggest to use
Readonly property of textbox instead of setting visible = false.
I am trying to code for "Hint Text in Text Box" in C#. It works this way:
Initially show "Hint Text" with inactive caption color
Blank the text box if all the hint text is selected
Shows the user input text (after typing in this)
If user deletes his text and goes to the next control, then it shows the hint text again.
I need a help on 2nd point: It's not clearing the text box if its content is not selected. It receives the input text mixed with "hint text".
On which event I need to write the code txtBox1.Clear(); to achieve my aim?
Assuming this is WinForms: Look at the Enter and Leave events. They will be called when a control gets or loses focus. You then need to decide whether the value in the text box is your default hint or entered by the user.
For WPF: There are nice solutions out there that use adorners to achieve what you want. You could google for WPF textbox watermark adorner.
I'm coding a textbox that auto suggest when I'm writing, but when autocomplete appear, if I press Down, my textBox1.Text change, therefore it call TextChanged function, and autocomplete list is being update.
I want while I press Down, the text dont change ultil I press Enter. Is any way to fix this issue?
Turn Off Autocomplete feature of textbox
<asp:TextBox Runat="server" ID="Textbox1" autocomplete="off"></asp:TextBox>
Apart from implementing your own autocomplete, such as by overriding OnTextChanged and showing a list, the only options to control the behavior of autocomplete on a WinForms TextBox are given by the AutoCompleteMode property and the enumeration of the same name. See C# AutoComplete for a related question.
Third party text boxes may have more options but I am not aware of any that do.
I'm making a typing windows program that has two text Boxes,
the first is the Source Text textBox and it is read only,
the other is where the user get to type in the text that is in the source TextBox.
When the user typing a letter in the TypingTextBox, I want that letter to be highlighted in the SourceTextBox..
I tried doing this in a couple of events, but none really worked:
SourceTextBox.Select(TypingTextBox.SelectionStart , 1);
I even Tried Making my own event, Also didn't work.
The thing is, I won't see the SourceTextBox highlighting unless I click on it.
and As I mentioned, I tried putting the above code in events like:
Mouse-Focus-Leave in the SourceTextBox
and: TextChanged in the TypingTextBox.
All didn't work .. :(
and If I manged to do that, Can I change the Highlight color ?
Assuming this is WinForm, you need to set the HideSelection property on the TextBox to "False". As far as changing the highlight colour, none that I'm aware of.
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?