Wednesday, April 15, 2020

[C#][Resolved] Readonly TextBox with ScrollBar

I want a readonly textarea show a long list of news.
But there is no textarea but multiline textbox.
So what should do is create a new TextBox with multiline:
TextBox textBox = new TextBox();
textBox.Multiline = true;
textBox.WordWrap = true;
textBox.ReadOnly = true;
textBox.Text = "your long text";

However, the overflowed content are hidden, let set a vertical scrollbar for user to view the hidden part, insert this line after your insert statment:
textBox.ScrollBars = ScrollBars.Vertical;

Reference:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.textbox.multiline?view=netframework-4.8

No comments :

Post a Comment