Search code examples
c#textboxprogrammatically-created

Make textbox multiline programmatically


I am creating my textbox within the runtime like this:

TextBox control = new TextBox();                        
control.Name = "txt" + "somename";

I searached on the internet and found that there should be a Multiline-Property in Textbox, but sadly I could not find it. I tried also to add multiple lines, but this isn't working either.

How can I do it within my code? I use Windowsforms and .NET Framework 4.7.2


Solution

  • control.Multiline = true;
    

    That will make your textbox multiline. Here is a fully working example:

    var textBox = new TextBox
    {
      Multiline = true
    };
    
    textBox.Text = "FirstLine" + Environment.NewLine + "SecondLine";