How to set a Textbox to allow multiple lines, and scrollability

15,504

Solution 1

$objTextBox1 = New-Object System.Windows.Forms.TextBox 
$objTextBox1.Multiline = $True;
$objTextBox1.Location = New-Object System.Drawing.Size(150,10) 
$objTextBox1.Size = New-Object System.Drawing.Size(300,200)
$objTextBox1.Scrollbars = "Vertical" 
$objForm1.Controls.Add($objTextBox1)

Options for Scrollbars can be "Vertical", "Horizontal", or "Both".

Solution 2

$objTextBox1 = New-Object System.Windows.Forms.TextBox 
$objTextBox1.Multiline = $True;
$objTextBox1.Location = New-Object System.Drawing.Size(150,10) 
$objTextBox1.Size = New-Object System.Drawing.Size(300,200)
$objTextBox1.Scrollbars = 3#Scrollbars.Vertical
$objForm1.Controls.Add($objTextBox1) 
Share:
15,504
M24Kermit
Author by

M24Kermit

Updated on June 04, 2022

Comments

  • M24Kermit
    M24Kermit about 2 years

    I am returning multiple different sizes of strings into a box. I have used a System.Windows.Forms.Label but unfortunately some of the strings are too large for it, and do not display. I have tried replacing it with a System.Windows.Forms.TextBox but it will not let me set the height of it past 1 line, even with multiline set to true, and scrollbars set:

    $objTextBox1 = New-Object System.Windows.Forms.TextBox 
    $objTextBox1.Multiline = True;
    $objTextBox1.Location = New-Object System.Drawing.Size(150,10) 
    $objTextBox1.Size = New-Object System.Drawing.Size(300,200)
    $objTextBox1.Scrollbars = Scrollbars.Vertical
    $objForm1.Controls.Add($objTextBox1) 
    

    Is there anything I'm missing here?