Question [resolu] timer

Plus d'informations
il y a 14 ans 2 mois #10967 par mehedi
[resolu] timer a été créé par mehedi
bonjour

J'aurai besoin d'aide pour petit script Powershell utilisant un timer.

j'aimerai que dans feuille form avec 2 champs texte que le bouton OK soit grisé pendant 5 secondes et soit automatiquement validé bout de 10 secondes.

Merci pour votre aide.<br><br>Message édité par: mehedij, à: 25/01/12 15:22

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

Plus d'informations
il y a 14 ans 1 mois #11032 par mehedi
Réponse de mehedi sur le sujet Re:timer
j'ai trouvé. ça ne me parait pas très élégant, j'ai utilisé une progressbar caché. Mais ça marche.

clear

[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
#
# Timer
$timer = new-object System.Windows.forms.timer
$timer.Interval = 100 # 1 seconde
#
# progressBar1
#
$progressBar1 = new-object System.Windows.Forms.ProgressBar
$progressBar1.Location = new-object System.Drawing.Point(58, 107)
$progressBar1.Name = 'progressBar1'
$progressBar1.Size = new-object System.Drawing.Size(164, 23)
$progressBar1.Value = 0
$progressbar1.style = 'continuous'
$progressbar1.step = 1
$progressbar1.Visible = $False
#
# Label1
#
$label1 = new-object System.Windows.Forms.Label
$label1.Location = new-object System.Drawing.Point(70, 70)
$label1.Size = new-object System.Drawing.Size(139,13)
$label1.Text = 'Style continuous :'

$textbox1 = new-object System.Windows.Forms.TextBox
$textbox1.Location = new-object System.Drawing.Point(70, 100)
$textbox1.Size = new-object System.Drawing.Size(139,13)
$textbox1.Text = 'nom utilisateur'

#
#boutton OK
#
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(120,240)
$OKButton.Size = New-Object System.Drawing.Size(50,20)
$OKButton.Text = \&quot;OK\&quot;
$OKButton.enabled = $false
$OKButton.Add_Click({$utilisateur=$textbox1.Text;$Form1.Close()})

$Form1 = new-object System.Windows.Forms.form
# Form1
#
$Form1.Controls.Add($label1)
$Form1.Controls.Add($textbox1)
$Form1.Controls.Add($OKButton)
$Form1.ClientSize = new-object System.Drawing.Size(284, 264)
$Form1.Controls.Add($progressBar1)

$Form1.Text = \&quot;Barre de progression - 1\&quot;




$timer.Add_Tick({
$progressBar1.PerformStep()
if ($progressBar1.Value -lt 100) {$val = $progressBar1.Value;$label1.Text =\&quot;Style continuous : $val %\&quot;}
if ($progressBar1.Value -gt 50) {$val = $progressBar1.Value;$label1.Text =\&quot;Style continuous : $val %\&quot;;$OKButton.enabled = $true}
if ($progressBar1.Value -eq 100) {$utilisateur=$textbox1.Text;$Form1.Close()}
})

$timer.Start()
$Form1.activate()
$Form1.ShowDialog()



$label2 = new-object System.Windows.Forms.Label
$label2.Location = new-object System.Drawing.Point(70, 70)
$label2.Size = new-object System.Drawing.Size(139,13)
$label2.Text = $utilisateur

$Form2 = new-object System.Windows.Forms.form
# Form1
#
$Form2.Controls.Add($label2)
$Form2.ClientSize = new-object System.Drawing.Size(284, 264)
$Form2.Text = \&quot;Résultat\&quot;
$Form2.Activate()
$Form2.ShowDialog()

[code:1]
clear

[void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
#
# Timer
$timer = new-object System.Windows.forms.timer
$timer.Interval = 100 # 1 seconde
#
# progressBar1
#
$progressBar1 = new-object System.Windows.Forms.ProgressBar
$progressBar1.Location = new-object System.Drawing.Point(58, 107)
$progressBar1.Name = 'progressBar1'
$progressBar1.Size = new-object System.Drawing.Size(164, 23)
$progressBar1.Value = 0
$progressbar1.style = 'continuous'
$progressbar1.step = 1
$progressbar1.Visible = $False
#
# Label1
#
$label1 = new-object System.Windows.Forms.Label
$label1.Location = new-object System.Drawing.Point(70, 70)
$label1.Size = new-object System.Drawing.Size(139,13)
$label1.Text = 'Style continuous :'

$textbox1 = new-object System.Windows.Forms.TextBox
$textbox1.Location = new-object System.Drawing.Point(70, 100)
$textbox1.Size = new-object System.Drawing.Size(139,13)
$textbox1.Text = 'nom utilisateur'

#
#boutton OK
#
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(120,240)
$OKButton.Size = New-Object System.Drawing.Size(50,20)
$OKButton.Text = \&quot;OK\&quot;
$OKButton.enabled = $false
$OKButton.Add_Click({$utilisateur=$textbox1.Text;$Form1.Close()})

$Form1 = new-object System.Windows.Forms.form
# Form1
#
$Form1.Controls.Add($label1)
$Form1.Controls.Add($textbox1)
$Form1.Controls.Add($OKButton)
$Form1.ClientSize = new-object System.Drawing.Size(284, 264)
$Form1.Controls.Add($progressBar1)

$Form1.Text = \&quot;Barre de progression - 1\&quot;




$timer.Add_Tick({
$progressBar1.PerformStep()
if ($progressBar1.Value -lt 100) {$val = $progressBar1.Value;$label1.Text =\&quot;Style continuous : $val %\&quot;}
if ($progressBar1.Value -gt 50) {$val = $progressBar1.Value;$label1.Text =\&quot;Style continuous : $val %\&quot;;$OKButton.enabled = $true}
if ($progressBar1.Value -eq 100) {$utilisateur=$textbox1.Text;$Form1.Close()}
})

$timer.Start()
$Form1.activate()
$Form1.ShowDialog()



$label2 = new-object System.Windows.Forms.Label
$label2.Location = new-object System.Drawing.Point(70, 70)
$label2.Size = new-object System.Drawing.Size(139,13)
$label2.Text = $utilisateur

$Form2 = new-object System.Windows.Forms.form
# Form1
#
$Form2.Controls.Add($label2)
$Form2.ClientSize = new-object System.Drawing.Size(284, 264)
$Form2.Text = \&quot;Résultat\&quot;
$Form2.Activate()
$Form2.ShowDialog()
[/code:1]

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

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