Question [Résolu] WinForm et le binding

Plus d'informations
il y a 16 ans 4 mois #5546 par manu_l63@hotmail.com
bonjour,

Je teste actuellement les forms avec powershell.
je fais un test simple:
une inputbox, et un label qui sert a faire l'echo de ce qui est mis dans l input.
Cela est genere au moment du onclick sur un bouton ok.
Comment reprendre la main apres avoir clique afin que soit pris en compte la modification du label?
Merci pour votre aide.

[code:1]

[void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Drawing\"«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\"System.Windows.Forms\"«»)

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = \"Data Entry Form\"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = \"CenterScreen\"

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = \"OK\"
$OKButton.add_click({
$objTextBox.text = $x
})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = \"Cancel\"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = \"Please enter the information in the space below:\"
$objForm.Controls.Add($objLabel)

$objLabel1 = New-Object System.Windows.Forms.Label
$objLabel1.Location = New-Object System.Drawing.Size(10,70)
$objLabel1.Size = New-Object System.Drawing.Size(280,20)
$objLabel1.Text = $x
$objForm.Controls.Add($objLabel1)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)

$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

[/code:1]<br><br>Message édité par: Arnaud, à: 12/11/09 00:26

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

Plus d'informations
il y a 16 ans 4 mois #5552 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:form et
Comme ceci :
[code:1]
$OKButton.add_click({
$objLabel1.Text=$objTextBox.Text
})
[/code:1]

Tutoriels PowerShell

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

Plus d'informations
il y a 16 ans 4 mois #5553 par Laurent Dardenne
Réponse de Laurent Dardenne sur le sujet Re:form et
On peut aussi utiliser le databinding.
[code:1]
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Drawing\&quot;«»)
[void] [System.Reflection.Assembly]::LoadWithPartialName(\&quot;System.Windows.Forms\&quot;«»)

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = \&quot;Data Entry Form\&quot;
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = \&quot;CenterScreen\&quot;

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = \&quot;OK\&quot;
$OKButton.add_click({
Write-host $objLabel1.Text
})
$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = \&quot;Cancel\&quot;
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = \&quot;Please enter the information in the space below:\&quot;
$objForm.Controls.Add($objLabel)

$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True

$objLabel1 = New-Object System.Windows.Forms.Label
$objLabel1.Location = New-Object System.Drawing.Size(10,70)
$objLabel1.Size = New-Object System.Drawing.Size(280,20)
$objLabel1.Text =\&quot;\&quot;
$objForm.Controls.Add($objLabel1)
#************* DataBinding **************
#Text est le nom des propriétés \&quot;liées\&quot;
$objLabel1.DataBindings.Add(\&quot;Text\&quot;, $objTextBox, \&quot;Text\&quot;«»)

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
[/code:1]
Ce que tu saisis dans le textBox est directement inséré dans le champ \&quot;Text\&quot; du label.

Tutoriels PowerShell

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

Plus d'informations
il y a 16 ans 4 mois #5582 par manu_l63@hotmail.com
Réponse de manu_l63@hotmail.com sur le sujet Re:form et
Bonjour,

Merci pour le coup de main et le databinding.

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

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