Question Modifier dynamiquement un élément d'une fenêtre

Plus d'informations
il y a 14 ans 1 semaine #11308 par Rampnoux
Bonjour,

Mon problème est probablement déjà traité mais je ne trouvé pas la solution.
J'ai créé une fenêtre avec un élément label qui a une propriété .BackColor dont je veux changer la valeur (soit explicitement, soit éventuellement via un timer).
J'ai bien regardé la progressbar mais ce n'est pas la solution, d'après la doc en lien depuis ce forum, ForeColor n'est pas pris en charge.

Merci de votre aide
Régis

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 14 ans 1 semaine #11319 par Laurent Dardenne
Salut,
as-tu un exemple de code à nous proposer ?

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 14 ans 6 jours #11323 par Rampnoux
Bonjour,

Voici le bout de code, j'ai juste changé le nom du site.
N'arrêtez pas le site pour tester quand même ;)
J'ai changé le nom du site, le mien était en interne, avant de proposer un choix.
[code:1]

[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')


$url=\"powershell-scripting.com/\";
$lsite = \"le meilleur site sur PowerShell\"

$xHTTP = new-object -com msxml2.xmlhttp;
$xHTTP.open(\"GET\",$url,$false);
$xHTTP.send();
$stat = $xHTTP.status;
$objForm2 = New-Object System.windows.Forms.Form
$objForm2.width = 330
$objForm2.height = 180
$objForm2.Text = \"Status site\"
$objTitle2 = new-object System.Windows.Forms.Label
$objTitle2.Location = new-object System.Drawing.Size(100,10)
$objTitle2.size = new-object System.Drawing.Size(200,20)
$objTitle2.Text = \"Status site \"
$objForm2.Controls.Add($objTitle2)


$objSubLabel2 = new-object System.Windows.Forms.Label
$objSubLabel2.Location = new-object System.Drawing.Size(120,50)
$objSubLabel2.Size = new-object System.Drawing.Size(200,20)
$objSubLabel2.Text = $lsite

$objForm2.Controls.Add($objSubLabel2)


$objSubLabel = new-object System.Windows.Forms.Label
$objSubLabel.Location = new-object System.Drawing.Size(120,80)
$objSubLabel.Size = new-object System.Drawing.Size(100,20)

if ($stat -eq \"200\" ) {
$objSubLabel.BackColor = \"green\";
$objSubLabel.ForeColor = \"white\";
$objSubLabel.Text = \" Etat: OK\"
}
if ($stat -eq \"500\" ) {
$objSubLabel.BackColor = \"red\";
$objSubLabel.ForeColor = \"white\";
$objSubLabel.Text = \" Etat: K0\"
}

$objForm2.Controls.Add($objSubLabel)

$objButtonOK2 = new-object System.Windows.Forms.Button
$objButtonOK2.Location = new-object System.Drawing.Size(130,110)
$objButtonOK2.Size = new-object System.Drawing.Size(50,20)
$objButtonOK2.Text = \"Ok\"
$objButtonOK2.Add_Click({
$cont = $False
$objForm2.Close()
})
$objForm2.Controls.Add($objButtonOK2)

$objForm2.Topmost = $True
$objForm2.Add_Shown({$objForm2.Activate()})
[void] $objForm2.ShowDialog()
while ($cont) {
sleep 10
$xHTTP.open(\"GET\",$url,$false);
$xHTTP.send();
if ($xHTTP.status -ne $stat) {
$stat = $xHTTP.status
if ($stat -eq \"200\" ) {
$objSubLabel.BackColor = \"green\";
$objSubLabel.ForeColor = \"white\";
$objSubLabel.Text = \" Etat: OK\";
$objSubLabel.refresh();
$objForm.refresh();
}
}
}
[/code:1]

Cordialement,
Régis

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.083 secondes
Propulsé par Kunena