基礎:
[System.Windows.Forms.PictureBoxSizeMode].GetEnumNames()
高級(含其對應的數字一起名稱):
[System.Enum]::GetNames([System.Windows.Forms.PictureBoxSizeMode])|
ForEach-Object {"{0} {1}" -f
[System.Windows.Forms.PictureBoxSizeMode]::$_.value__, $_ }
此外,在代碼審查我的回答比較Get-EnumValue
功能(自定義cmdlet的)來Getting enum values of Pseudo-Enum classes。
編輯
所有上述含在powershell_ise
[System.Windows.Forms.PictureBoxSizeMode]
運行代碼。不幸的是,powershell
提高TypeNotFound
錯誤:
PS D:\PShell> [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
Unable to find type [System.Windows.Forms.PictureBoxSizeMode]. Make sure that the assembly that contains this type is loaded. At line:1 char:1
+ [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Windows.Forms.PictureBoxSizeMode:TypeName) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
我們需要再次向System.Windows.Forms
命名空間的引用;一些消息來源勸續訂參考System.Drawing
還有:
PS D:\PShell> [void] (Add-Type -AssemblyName System.Windows.Forms -PassThru)
PS D:\PShell> [void] (Add-Type -AssemblyName System.Drawing -PassThru)
PS D:\PShell> [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
StretchImage
PS D:\PShell> [System.Windows.Forms.PictureBoxSizeMode]::StretchImage.value__
1
PS D:\PShell>
'[System.Windows.Forms.PictureBoxSizeMode] :: StretchImage' – TessellatingHeckler
您需要的命名空間,就像任何其他類型。 – SLaks
'$ pictureBox.SizeMode ='StretchImage'' – PetSerAl