In my WinForms application, I have fixed-size multiline textboxes that can contain a variable number of lines. I want the textboxes to fit two lines plus tax in them so that only the upper part of the third line is displayed when a third line is present. Unfortunately, the third line is not displayed at all and there's just empty space instead -- you need to scroll down to see it. This is not good because the idea is to indicate to the user that scrolling down might be necessary. Is it possible to force the textbox to display the upper part of the third line?
Asked
Active
Viewed 118 times
5
-
1@GrantWinney It does, but the change in color is not very impressive and the arrows are pretty small. This should be obvious to the user because the application is going to be used by service desk technicians who are generally solving three to four enduser problems at once. It's unfortunate but that's our work environment currently and it could lead to mistakes. – Michał Masny Feb 01 '16 at 02:49
-
The comment above is a response to the question: "Isn't the scrollbar indication enough?" – Michał Masny Feb 01 '16 at 02:50
-
[This SO post](http://stackoverflow.com/questions/6045641/using-graphics-drawstring-to-simulate-textbox-rendering) is worth a read. Sounds like implementing this solution will require fiddling around with how the text box draws itself, which might be a deceptively difficult proposition -- although I fully agree that the out-of-the-box implementation does a poor job at indicating more text is present by not drawing that partial "third line" of text. – Lemonseed Feb 08 '16 at 08:10
2 Answers
3
Perhaps you could use the RichTextBox class, which displays partial lines by default. It is derived from the same base class as TextBox (TextBoxBase), so it should be a drop-in replacement.
cokeman19
- 2,405
- 1
- 25
- 40
3
I don't think you can do this out-of-the-box. But, there are 2 ways that I can think of by which you can achieve your goal
- Do you really need a
TextBoxcontrol. Can aLabelwork for you. If yes, thenLabeldoes not have the problem you describe above. If not, then you can use a nifty trick to always display your contents in aLabeland switch it to aTextBoxwhen a user starts typing. - Another way is to disable scrolling in the TextBox. Adjust the height of the
TextBoxto 3 clearly visible lines. Now drop thisTextBoxinto aPanel. Make sure thePanelusesPanel.AutoScroll = true(you can use a separateVerticalScrollbarorHorizontalScrollbaror both if you need more control). Now adjust thePanel.Heightso that only 2 full lines are visible and the 3rd line is partially visible.
You mentioned that your TextBox
can contain a variable number of lines
But you also mentioned
I want the textboxes to fit two lines plus tax in them so that only the upper part of the third line is displayed when a third line is present
So not sure what is the case. If you need to dynamically adjust the height of your TextBox, then look at this post to Autoresize textbox control vertically