none
Windows Form action problem since powershell 3.0 RRS feed

  • Frage

  • problem since powershell version 3.0

    my grafical forms doesn't execute the variable assignment  $eval=$true, if i click  the ok button

    here the code:

    $eval=$false

    $ok=new-object system.windows.forms.button
        $ok.text="JA/SI"
        $ok.top=$fxdeutsch.top+$fxdeutsch.height+30
        $ok.left=40
        $ok.add_Click({$eval=$true;$form.close();$form.dispose()})
        #Focus auf Ok legen
        $ok.tabindex = 0  
        $form.controls.add($ok)

    Any sugestion

    Donnerstag, 6. Dezember 2012 14:13

Antworten

  • Zunächst einmal kann ich dir bestätigen das sich PowerShell 2.0 und 3.0 unterschiedlich verhalten.

    Wie ich vermutet habe ist dies ein Scope Problem: http://www.colorconsole.de/PS_Windows/de/about_scopes.htm

    So geht es bei mir in 2.0 und 3.0:

    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    
    $form1 = New-Object System.Windows.Forms.Form
    $button1 = New-Object System.Windows.Forms.Button
    
    $form1.ClientSize = "200,200"
    $form1.Name = "form1"
    
    $button1.DataBindings.DefaultDataSourceUpdateMode = 0
    
    
    $button1.Location = "5,5"
    $button1.Name = "button1"
    $button1.Size = "75,23"
    $button1.TabIndex = 0
    $button1.Text = "JA/SI"
    
    
    # -- begin TEST area >>
    
    $eval = $False
    
    $button1.add_Click({$Script:eval = $True;$form1.close();$form1.Dispose()})
    
    # << end Test area --
    
    $form1.Controls.Add($button1)
    $form1.ShowDialog()| Out-Null
    
    Write-Host "eval ist $eval"


    Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
    German ? Come to German PowerShell Forum!


    Donnerstag, 6. Dezember 2012 16:09

Alle Antworten