我正在编写一些PowerShell代码以用于以后的项目。这是一个列表,用户可以从中选择一个项目,并将选择项分配给一个变量。我不确定如何控制字体大小,特别是对于列表框文本。
这是代码:
# 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 Esc to close windowed prompt
#
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objListBox.SelectedItem;$objForm.Close()}}) …Run Code Online (Sandbox Code Playgroud)