본문 바로가기
파워쉘(Powershell)/파워쉘 GUI

Label - Powershell GUI

by 예배파 2024. 3. 19.

Winform에서 글자들을 표시할 때 사용되는 컨트롤

클래스 이름 : System.Windows.Forms.Label

 

 

기본 사용방법

Add-Type -AssemblyName System.windows.Forms

$form= New-Object System.Windows.Forms.Form    
$form.Size = '200,100'                         

$lbl = New-Object System.Windows.Forms.Label   # Label 객체 생성
$lbl.Location = '10,10'                        # 가로 10, 세로 10 위치 
$lbl.Text = 'Hello'                            # Text속성에 'Hello' 문자열 입력

$form.Controls.Add($lbl)                       
$form.ShowDialog()

 

 

 

 

 

 

 

색깔 변경 방법

 

글자의 색(ForeColor), 글자의 배경색(BackColor)변경

$lbl = New-Object System.Windows.Forms.Label   
$lbl.Location = '10,10'                        
$lbl.Text = 'Hello'                            

$lbl.ForeColor = 'Blue'     #글자 색깔을 파란색으로 변경
$lbl.BackColor = 'Red'      #글자 배경색을 빨간색으로 변경

 

 

 

 

 

 

글자 폰트(Font) 변경

 

$lbl = New-Object System.Windows.Forms.Label   
$lbl.Location = '10,10'                        
$lbl.Text = 'Hello'                            

$lbl.Font = [System.Drawing.Font]::new("Microsoft Sans Serif", 14, [System.Drawing.FontStyle]::Bold)

 

Label의 폰트를 Microsoft Sans Serif  , 글자 크기를 14, 글자를 두껍게(Bold)로 변경