Powershell – Création interface GUI

[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Collections')
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.ComponentModel')
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Data')

$Ajouter = New-Object System.Windows.Forms.Button
$AdresseIP = new-object System.Windows.Forms.Label
$Liste_IP = new-object System.Windows.Forms.TextBox
$TXTNomConnecteurServeur = new-object System.Windows.Forms.CheckBox
$TXTNomConnecteurCopieur = new-object System.Windows.Forms.CheckBox
$TXTNomConnecteurRelais = new-object System.Windows.Forms.CheckBox
$TXTNomConnecteurAS400 = new-object System.Windows.Forms.CheckBox
$GroupBox1 = New-Object System.Windows.Forms.GroupBox

# Bouton
$Ajouter.Text = "Ajouter"
$Ajouter.Location = New-Object System.Drawing.Size(100, 245)
$Ajouter.Size = New-Object System.Drawing.Size(90,30)
$Ajouter.Add_Click({AjoutAdresseIP})

# TEXTE
$AdresseIP.AutoSize = $true
$AdresseIP.Location = new-object System.Drawing.Point(10, 130)
$AdresseIP.Name = "AdresseIP"
$AdresseIP.Size = new-object System.Drawing.Size(21, 13)
$AdresseIP.TabIndex = 2
$AdresseIP.Text = "Adresse IP :"

# Groupe Box
$GroupBox1 = New-Object System.Windows.Forms.GroupBox
$GroupBox1.Location = New-Object System.Drawing.Size(10,10)
$GroupBox1.size = New-Object System.Drawing.Size(100,100)
$GroupBox1.text = "Nom du connecteur :"
$GroupBox1.AutoSize = $True

# Bouton radio Groupe Box
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = new-object System.Drawing.Point(15,15)
$RadioButton1.size = New-Object System.Drawing.Size(200,20)
$RadioButton1.Checked = $true
$RadioButton1.Text = "SERVEURS"
$GroupBox1.Controls.Add($RadioButton1)

# Bouton radio Groupe Box
$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = new-object System.Drawing.Point(15,35)
$RadioButton2.size = New-Object System.Drawing.Size(200,20)
$RadioButton2.Text = "COPIEURS"
$GroupBox1.Controls.Add($RadioButton2)

# Bouton radio Groupe Box
$RadioButton3 = New-Object System.Windows.Forms.RadioButton
$RadioButton3.Location = new-object System.Drawing.Point(15,55)
$RadioButton3.size = New-Object System.Drawing.Size(200,20)
$RadioButton3.Text = "RELAIS EXTERNE"
$GroupBox1.Controls.Add($RadioButton3)

# Bouton radio Groupe Box
$RadioButton4 = New-Object System.Windows.Forms.RadioButton
$RadioButton4.Location = new-object System.Drawing.Point(15,75)
$RadioButton4.size = New-Object System.Drawing.Size(200,20)
$RadioButton4.Text = "AS400"
$GroupBox1.Controls.Add($RadioButton4)

# Zone de saisie
$Liste_IP.AutoSize = $false
$Liste_IP.Location = new-object System.Drawing.Point(120, 130)
$Liste_IP.Name = "TXTAdresseIP"
$Liste_IP.Size = new-object System.Drawing.Size(150, 100)
$Liste_IP.TabIndex = 4
$Liste_IP.Text = "127.0.0.1"
$Liste_IP.Multiline = $true

# Mise en forme
$Form1 = new-object System.Windows.Forms.form
$Form1.ClientSize = new-object System.Drawing.Size(300, 290)
$Form1.Controls.Add($AdresseIP)
$Form1.Controls.Add($GroupBox1)
$Form1.Controls.Add($Liste_IP)
$Form1.Controls.Add($Ajouter)
$Form1.Name = "Form1"
$Form1.Text = "Ajouter adresse IP dans connecteur"
$Form1.ShowDialog()

Function AjoutAdresseIP {

If ($RadioButton1.Checked -eq $true) {$ConnectorName="SERVEURS"}
If ($RadioButton2.Checked -eq $true) {$ConnectorName="COPIEURS"}
If ($RadioButton3.Checked -eq $true) {$ConnectorName="RELAIS_EXTERNE"}
If ($RadioButton4.Checked -eq $true) {$ConnectorName="AS400"}

$date = Get-Date -Format "yyyy-MM-dd_H\hmm" # Recuperation de la date et heure du jours

$Texte1 = "Vous avez rajouté sur le connecteur : " + $ConnectorName + "`n"
$Texte2 = "Avec les adresse IP : `n"
$Texte3 = $Liste_IP -replace "System.Windows.Forms.TextBox, Text: ", ""

$oReturn=[System.Windows.Forms.MessageBox]::Show($Texte1 + $Texte2 + $Texte3,"Controle de saisie",[System.Windows.Forms.MessageBoxButtons]::OKCancel)

switch ($oReturn) {
"OK" {
write-host "Saisie valide"

Foreach ($IP in $Texte3) {

}
}
"Cancel" {
write-host "Saisie non valide"
# Enter some code
}
}
}

 

Taggé , .Mettre en favori le Permaliens.

Les commentaires sont fermés.