【发布时间】:2016-12-21 01:47:31
【问题描述】:
我一直在 Powershell 中设计一个 GUI(从没想过我会使用这句话),并且在查看不同的在线资源时,有不同的方法可以在表单中定位控制项。
当我第一次开始熟悉如何构建简单表单的基本框架时,它显示了这一点:
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$form = New-Object System.Windows.Forms.Form
$button = New-Object System.Windows.Forms.Button
$button.Top = 30
$button.Left = 30
$form.Controls.Add($button)
但是,环顾四周,我看到大多数地方都使用这种方法:
[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
$form = New-Object System.Windows.Forms.Form
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Size(30,30)
$form.Controls.Add($button)
它似乎完成了完全相同的事情。
做同一件事的不同方法使编程变得有趣(无论如何,对我来说)。我想知道的是,后者是否更普遍地被证明是有原因的,是否有原因。
谢谢。
【问题讨论】:
标签: winforms powershell user-interface system.drawing