I do not know how to add a bold shortcut in powershell winforms

I tried several things from different posts, but I just can't make it bold.

Does anyone know how to do this?

$LabelComputer = New-Object System.Windows.Forms.Label
$LabelComputer.Text = "Computer Settings"
$LabelComputer.AutoSize = $True
$LabelComputer.Top="5" 
$LabelComputer.Left="10" 
$LabelComputer.Anchor="Left,Top" 
$form1.Controls.Add($LabelComputer)
+5
source share
5 answers

You will need to create an object Fontand pass it to a property Fontin the label control.

Unfortunately, with these objects you need to give a few things in the constructor, so you cannot just create an empty object and fill it with such details as you can with a label.

For this purpose, you can do this before adding a control to your form:

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

, new(...) :

  • ( , 1)
  • , .

.

: , $LabelFont, $LabelComputer.Font = $LabelFont.

+3

, , Lable, Font.

$LabelComputer = New-Object System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)

, .

+1

:

$LabelComputer.Font.Bold = $true
0

powershell, [System.Drawing.Font]::new powershell 2.0 ( 5.1).

, . :

$LabelComputer.Font = New-Object System.Drawing.Font("Arial",8,[System.Drawing.FontStyle]::Bold) 

: , , , ,

0
source

Adding to @ToTi above, the following worked for me (verified with 5.1)

$LabelComputer.Font = new-object System.Drawing.Font('Ariel',8,[System.Drawing.FontStyle]::Bold)
0
source

Source: https://habr.com/ru/post/1679576/


All Articles