Bonjour, J’ai ce qui semble un bug de Windows PowerShell que je ne retrouve pas avec les éditeurs de PowerShell comme Windows PowerShell ISE et n’arrive pas à le contourner, pourriez-vous m’aider s’il vous plait.
Au clic sur un bouton, si je lance une fonction comme « Start-Sleep -Milliseconds 5000 » ou autre
Apres avoir voulu changer un libellé et grisé un bouton comme suit
Si je lance le script avec un éditeur comme Windows PowerShell ISE cela fonctionne bien mais si je le lance avec Windows PowerShell le grisé se met bien mais pas le changement de libellé.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 $lbl_Result.Text = "Génération du fichier XLS en cours. Veuillez patienter..." $btn_Export.Enabled = $false Start-Sleep -Milliseconds 5000 $frm_Main.Close()
Si je retire la fonction Start-Sleep ou autre cela fonctionne bien…
Pour tester Il suffit de mettre le code ci-dessous dans un fichier Test.PS1 à déposer directement sous C :
Faire démarrer
Taper po
Cliquer sur
Windows PowerShell
Taper C:\Test.PS1 et Entrée
Constater que le libellé affiché « Lancer la génération du XLS »
Cliquer sur le bouton lancer …
Constater que le libellé affiché reste si on passe par Windows PowerShell mais se change bien si on utilise un éditeur de powershell comme Windows PowerShell ISE
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null $frm_Main = New-Object System.Windows.Forms.Form $btn_Export = New-Object System.Windows.Forms.Button $lbl_Result = New-Object System.Windows.Forms.Label $btn_Export_OnClick= { $lbl_Result.Text = "Génération du fichier XLS en cours. Veuillez patienter..." $btn_Export.Enabled = $false Start-Sleep -Milliseconds 5000 $frm_Main.Close() } #region Formulaire $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 435 $System_Drawing_Size.Height = 550 $frm_Main.ClientSize = $System_Drawing_Size $frm_Main.StartPosition = "CenterScreen" $frm_Main.MaximizeBox = $false; $frm_Main.MinimizeBox = $false; #endregion #region Bouton - Lancement $btn_Export.TabIndex = 16 $btn_Export.Name = 'btn_Export' $btn_Export.Size = New-Object System.Drawing.Size(425,30) $btn_Export.Location = New-Object System.Drawing.Point(5,515) $btn_Export.UseVisualStyleBackColor = $True $btn_Export.Visible = $true $btn_Export.Text = 'Lancer la génération du XLS' $btn_Export.add_Click($btn_Export_OnClick) $frm_Main.Controls.Add($btn_Export) #endregion #region Label - Result $lbl_Result.Font = new-object System.Drawing.Font('Verdana', 10, [System.Drawing.FontStyle]::Bold, [System.Drawing.GraphicsUnit]::Point,0) $lbl_Result.Size = New-Object System.Drawing.Size(435,35) $lbl_Result.Location = new-object System.Drawing.Point(5,475) $lbl_Result.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter $lbl_Result.Forecolor = [System.Drawing.Color]::Green $lbl_Result.Name = 'lbl_Result' $lbl_Result.Text = 'Lancer la génération du XLS' $frm_Main.Controls.Add($lbl_Result) #endregion #Save the initial state of the form $InitialFormWindowState = $frm_Main.WindowState #Show the Form $frm_Main.ShowDialog()| Out-Null
Partager