如何更改Powershell中列表框的字体大小

我正在写一些PowerShell的代码来使用以后的项目。 这是一个列表,用户从列表中select一个项目,并将select分配给一个variables。 我不确定如何控制字体大小,特别是列表框文本。 这里是代码。

#Creates a window that prompts a user to select an item from a list #Enables .net Framework Classes Add-Type -AssemblyName System.Windows.Forms Add-Type -AssemblyName System.Drawing #Creates the window prompt $objForm = New-Object System.Windows.Forms.Form $objForm.Text = "Select an Item" $objForm.Size = New-Object System.Drawing.Size(600,500) $objForm.StartPosition = "CenterScreen" #defines Keystrokes as inputs #sets enter to set highlighted item to a variable #sets escape to close windowed prompt $objForm.KeyPreview = $True $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") {$x=$objListBox.SelectedItem;$objForm.Close()}}) $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$objForm.Close()}}) #Creates the OK button for the window $OKButton = New-Object System.Windows.Forms.Button $OKButton.Location = New-Object System.Drawing.Size(75,300) $OKButton.Size = New-Object System.Drawing.Size(100,35) $OKButton.Text = "OK" $OKButton.Add_Click({$x=$objListBox.SelectedItem;$ObjForm.Close()}) $objForm.Controls.Add($OKButton) #Creates the cancel button for the window $CancelButton = New-Object System.Windows.Forms.Button $CancelButton.Location = New-Object System.Drawing.Size(200,300) $CancelButton.Size = New-Object System.Drawing.Size(100,35) $CancelButton.Text = "Cancel" $CancelButton.Add_Click({$objForm.Close()}) $objForm.Controls.Add($CancelButton) #Adds the label text $objLabel = New-Object System.Windows.Forms.Label $objLabel.Location = New-Object System.Drawing.Size(10,40) $objLabel.Size = New-Object System.Drawing.Size(400,50) $objLabel.Text = "Please Select an Item" $objForm.Controls.Add($ObjLabel) #Creates the empty List box $objListBox = New-Object System.Windows.Forms.ListBox $objListBox.Location = New-Object System.Drawing.Size(10,100) $objListBox.Size = New-Object System.Drawing.Size(500,300) $objListBox.Height = 200 #Adds items to the list box #can call items from file # ex: Get-Content C:\Scripts\Test.txt | ForEach-Object {[void] $objListBox.Items.Add($_)} [void] $objListBox.Items.Add("one") [void] $objListBox.Items.Add("two") [void] $objListBox.Items.Add("three") [void] $objListBox.Items.Add("four") [void] $objListBox.Items.Add("five") $objForm.Controls.Add($objListBox) $objForm.Topmost = $True $objForm.Add_Shown({$objForm.Activate()}) [void] $objForm.ShowDialog() $x 

这是ListBox类的MSDN。 有一个属性称为字体 。 在MSDN的字体页面上可以看到所有的构造函数或者制作Font对象的方法。 在这个例子中,这是我用过的 。

 #Creates the empty List box $objListBox = New-Object System.Windows.Forms.ListBox $objListBox.Location = New-Object System.Drawing.Size(10,100) $objListBox.Size = New-Object System.Drawing.Size(500,300) $objListBox.Height = 200 $objListBox.Font = New-Object System.Drawing.Font("Lucida Console",12,[System.Drawing.FontStyle]::Regular)