A seguinte melhoria da minha resposta anterior à sua quase a mesma pergunta poderia ajudar, no entanto, essa colcha de retalhos o conduziria à perdição (assim como eu). Boa sorte!
Remove-Variable script:Part* -ErrorAction SilentlyContinue
$script:PartialResult = ''
$script:PartOperation = ''
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#Platfrom
### unchanged code here (cca 110 lines)
#Dezimalstelle
$Punkt = New-Object System.Windows.Forms.Button
$Punkt.Location = New-Object System.Drawing.Size(225,270)
$Punkt.Size = New-Object System.Drawing.Size(100,50)
$Punkt.Add_Click({$Textfeld.Text+='.'})
$Punkt.Text = "."
$Punkt.Name = "."
$Taschenrechner.Controls.Add($Punkt)
#Gleich
$gleich = New-Object System.Windows.Forms.Button
$gleich.Location = New-Object System.Drawing.Size(325,270)
$gleich.Size = New-Object System.Drawing.Size(100,50)
$gleich.Text = "="
$gleich.Name = "="
$Taschenrechner.Controls.Add($gleich)
#Durch
$durch = New-Object System.Windows.Forms.Button
$durch.Location = New-Object System.Drawing.Size(425,120)
$durch.Size = New-Object System.Drawing.Size(100,50)
$durch.Text = "/"
$durch.Name = "/"
$Taschenrechner.Controls.Add($durch)
#Mal
$mal = New-Object System.Windows.Forms.Button
$mal.Location = New-Object System.Drawing.Size(425,170)
$mal.Size = New-Object System.Drawing.Size(100,50)
$mal.Text = "×"
$mal.Name = "*"
$Taschenrechner.Controls.Add($mal)
#Minus
$minus = New-Object System.Windows.Forms.Button
$minus.Location = New-Object System.Drawing.Size(425,220)
$minus.Size = New-Object System.Drawing.Size(100,50)
$minus.Text = "-"
$minus.Name = "-"
$Taschenrechner.Controls.Add($minus)
#Plus
$plus = New-Object System.Windows.Forms.Button
$plus.Location = New-Object System.Drawing.Size(425,270)
$plus.Size = New-Object System.Drawing.Size(100,50)
$plus.Text = "+"
$plus.Name = "+"
$Taschenrechner.Controls.Add($plus)
Function Operation {
param([string] $Ope)
### you need to show partial result an operation!!!
if ( $Textfeld.Text -ne '' ) {
if ($script:PartialResult -ne '' ) {
$aux = [string] $script:PartialResult + $script:PartOperation + $script:Textfeld.Text
$script:PartialResult = [string] $( Invoke-Expression $aux )
} else {
$script:PartialResult = $Textfeld.Text
}
if ( $Ope -eq '=' ) {
$Textfeld.Text = '' + [string] $script:PartialResult
$script:PartialResult = ''
$script:PartOperation = ''
} else {
$Textfeld.Text = ''
$script:PartOperation = $Ope
}
}
}
$gleich.Add_Click( { Operation '=' } )
$mal. Add_Click( { Operation '*' } ) # Name = "×"
$plus. Add_Click( { Operation '+' } ) # Name = "+"
$minus. Add_Click( { Operation '-' } ) # Name = "-"
$durch. Add_Click( { Operation '/' } ) # Name = "/"
[void] $Taschenrechner.ShowDialog()