TextBox는 글자만 표시할 수 있지만,
RichTextBox는 글자의 폰트, 크기, 색깔등을 변경할 수 있습니다
사용방법
Add-Type -AssemblyName System.windows.Forms
$form= New-Object System.Windows.Forms.Form
$form.Size = '300,300'
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.Location = '10,10'
$rtb.Size = '250,200'
$rtb.AppendText("Hello")
$rtb.AppendText("How are you?"+"`r`n")
$rtb.AppendText("Good`r`n")
$s = "Have a nice day"
$rtb.AppendText($s)
$form.Controls.Add($rtb)
$form.ShowDialog()
RichTextBox에 글자들을 추가할 때는 AppendText를 사용합니다
AppendText는 문자열을 줄바꿈 없이 앞 문장에 붙여서 출력하기 때문에 줄바꿈 문자를 추가시켜야 합니다
줄바꿈은 "`r`n"을 사용합니다
글자 색깔, 폰트, 크기 바꾸기
SelectionFont, SelectionColor를 사용해서 글자의 색깔과 폰트 변환
Add-Type -AssemblyName System.windows.Forms
$form= New-Object System.Windows.Forms.Form
$form.Size = '300,300'
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.Location = '10,10'
$rtb.Size = '250,200'
$rtb.Font = [System.Drawing.Font]::new('Calibri', 14,[System.Drawing.FontStyle]::Bold)
$rtb.SelectionColor = 'Blue'
$rtb.AppendText("Hello"+ "`r`n")
$rtb.AppendText("How are you?"+"`r`n")
$rtb.SelectionColor = 'Red'
$rtb.AppendText("Good`r`n")
$form.Controls.Add($rtb)
$form.ShowDialog()
좌우 여백 넣기
SelectionIndent : 왼쪽여백
SelectionRightIndent : 오른쪽여백
Add-Type -AssemblyName System.windows.Forms
$form= New-Object System.Windows.Forms.Form
$form.Size = '300,300'
$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.Location = '10,10'
$rtb.Size = '250,200'
$rtb.SelectionIndent = 60
$rtb.SelectionRightIndent = 60
$rtb.AppendText("111111111111111111111111111"+ "`r`n")
$rtb.AppendText("222222222222222222222222222"+"`r`n")
$rtb.AppendText("Good`r`n")
$form.Controls.Add($rtb)
$form.ShowDialog()
'파워쉘(Powershell) > 파워쉘 GUI' 카테고리의 다른 글
파워쉘 트리뷰(Treeview) (0) | 2024.04.01 |
---|---|
파워쉘 DataGridView (0) | 2024.03.29 |
파워쉘 콤보박스 (Powershell ComboBox) (0) | 2024.03.28 |
파워쉘 라디오버튼(Powershell Radio button) (0) | 2024.03.27 |
파워쉘 텍스트박스(Powershell Textbox) (0) | 2024.03.22 |