mardi 18 décembre 2012

Powershell - Form





[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") 

$form = new-object Windows.Forms.form   
$form.Size = new-object System.Drawing.Size @(480,400)   
$form.text = "essai graphique 12/04/2007"

$boutton = new-object System.Windows.Forms.Button
$boutton.Text = 'Valider'
$boutton.Location = new-object System.Drawing.Size(300,155)  
$boutton.size = new-object System.Drawing.Size(120,30)
$boutton.add_Click({$nom=$listbox.get_selecteditem();$label2.text = "Reponse : " + $nom})

$label = New-Object System.Windows.Forms.Label
$label.text = "Qui est le meilleur en powershell ?"
$label.set_ForeColor("Green")
$label.Location = new-object System.Drawing.Size(55,30)  

$label.size = new-object System.Drawing.Size(200,20)
$label2 = New-Object System.Windows.Forms.Label
$label2.Location = new-object System.Drawing.Size(310,220)  
$label2.size = new-object System.Drawing.Size(180,20)

$listbox = new-object System.Windows.Forms.ListBox
[void]$listbox.Items.Add("Arnaud")
[void]$listbox.Items.Add("Robin")
[void]$listbox.Items.Add("Un autre")
[void]$listbox.Items.Add("Un autre2")
[void]$listbox.Items.Add("Un autre2")
[void]$listbox.Items.Add("Un autre2")
$listbox.Location = new-object System.Drawing.Size(50,75)  
$listbox.size = new-object System.Drawing.Size(200,200)

$form.Controls.Add($boutton)
$form.Controls.Add($listbox)
$form.Controls.Add($label)
$form.Controls.Add($label2)

$Form.Add_Shown({$form.Activate()})
[void]$form.showdialog()


Aucun commentaire:

Enregistrer un commentaire