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?
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
TextBox
control. Can a Label
work for you. If yes, then Label
does not have the problem you describe above. If not, then you can use a nifty trick to always display your contents in a Label
and switch it to a TextBox
when a user starts typing.TextBox
to 3 clearly visible lines. Now drop this TextBox
into a Panel
. Make sure the Panel
uses Panel.AutoScroll = true
(you can use a separate VerticalScrollbar
or HorizontalScrollbar
or both if you need more control).
Now adjust the Panel.Height
so 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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With