1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows Form を作成する PowerShell コードを見やすくする

Posted at

PowerShell で、System.Windows.Forms のアセンブリを利用して、Windows Form を作成するとき、例えば Label なら

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(250,20)
$label.Text = "Example of code to display labels"

のように書くところを、Property とハッシュテーブルを用いて

$label = New-Object System.Windows.Forms.Label -Property @{
    Location = New-Object System.Drawing.Point(10,20)
    Size = New-Object System.Drawing.Size(250,20)
    Text = "Example of code to display labels"
}

と書くことによって、見やすくできます。

また、LocationSize

$label = New-Object System.Windows.Forms.Label -Property @{
    Location = "10, 20"
    Size = "250, 20"
    Text = "Example of code to display labels"
}

と書くことによって、もっと見やすくできます。

なんなら、SizeAutoSize = $true に置き換えると、サイズをいくつにしようか悩まなくてすみます。

$label = New-Object System.Windows.Forms.Label -Property @{
    Location = "10, 20"
    AutoSize = $true
    Text = "Example of code to display labels"
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?