Is it possible to show the top of a line that does not match an integer in a multi-line text box?

In my WinForms application, I have fixed-size multi-line text fields that can contain a variable number of lines. I want the text fields to correspond to two lines, plus the tax in them, so that only the top of the third line is displayed when the third line is present. Unfortunately, the third line is not displayed at all, and instead of it just an empty place - you need to scroll down to see it. This is not good, because the idea is to tell the user that scrolling may be required. Is it possible to make the text box display the top of the third line?

+5
source share
2 answers

I do not think you can do this out of the box. But there are two ways that I can think with which you can achieve your goal.

  • You really need a TextBox control. Can Label work for you. If so, then Label does not have the problem described above. If not, you can use a great trick to always display your content in Label and switch it to TextBox when the user starts typing.
  • Another way is to disable scrolling in the TextBox. Adjust the height of the TextBox to 3 clearly visible lines. Now drop this TextBox in the Panel . Make sure Panel uses Panel.AutoScroll = true (you can use a separate VerticalScrollbar or HorizontalScrollbar or both, if you need more control). Now adjust Panel.Height so that only two full lines are visible, and the 3rd line is partially visible.

You mentioned that your TextBox

may contain a variable number of rows

But you also mentioned

I want the text fields to correspond to two lines, plus the tax in them, so that only the top of the third line is displayed.

So I'm not sure what the matter is. If you need to dynamically adjust the height of your TextBox , look at this message in Manage Autoresize Text Box Vertically

+3
source

Perhaps you could use the RichTextBox class, which by default shows partial lines. It is derived from the same base class as TextBox ( TextBoxBase ), so it should be a replacement.

+3
source

Source: https://habr.com/ru/post/1241962/


All Articles