PowerShell – die besten Beiträge

Wieso funktionier bei mir [System.Windows.MessageBox]::Show($DropDown)::OK in PowerShell nicht??

Hallo,
wo liegt die Fehler wieso funktioniert der [System.Windows.MessageBox]::Show($DropDown)::OK Befehl in meiner Code nicht??

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

  [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

  

  $Form = [System.Windows.Forms.MessageBox]::OK

   

  $Form.width = 300

  $Form.height = 150

  $Form.Text = ”DropDown”

  

  $DropDown = [System.Windows.MessageBox]::Show($DropDown)::OK

  $DropDown.Location = new-object System.Drawing.Size(100,10)

  $DropDown.Size = new-object System.Drawing.Size(130,30)

  ForEach ($Item in $DropDownArray) {

   [void] $DropDown.Items.Add($Item)

  }

  $Form.Controls.Add($DropDown)

  $DropDownLabel = [System.Windows.MessageBox]::Show($DropDown)::OK

  $DropDownLabel.Location = new-object System.Drawing.Size(10,10) 

  $DropDownLabel.size = new-object System.Drawing.Size(100,40) 

  $DropDownLabel.Text = "Suchen Sie die Pfad aus"

  $Form.Controls.Add($DropDownLabel)

    $Form.Controls.Add($DropDown)

  $DropDownLabel = [System.Windows.MessageBox]::Show($Form)::OK

  $DropDownLabel.Location = new-object System.Drawing.Size(10,10) 

  $DropDownLabel.size = new-object System.Drawing.Size(100,40) 

  $DropDownLabel.Text = "Zeit"

  $Form.Controls.Add($DropDownLabel)

  $Button = [System.Windows.MessageBox]::Show($Button)::OK

  $Button.Location = new-object System.Drawing.Size(100,50)

  $Button.Size = new-object System.Drawing.Size(100,20)

  $Button.Text = "Weiter"

  $Button.Add_Click({Return-DropDown})

  $form.Controls.Add($Button)

$result=[System.Windows.MessageBox]::Show($Form,$Button,$DropDownLabel,$DropDown,[System.Windows.MessageBoxResult]::OK)

   

  return $script:choice

Code, PowerShell

PowerShell mit mehreren Checkboxen?

Wenn ich die zweite CheckBox anhake wird der Befehl nicht ausgeführt bei der ersten wird er aber ausgeführt. Wie muss ich vorgehen dass beide CheckBoxen funktionieren.

Mein Script sieht so aus

function Test{

 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

 # Set the size of your form

 $Form = New-Object System.Windows.Forms.Form

 $Form.width = 435

 $Form.height = 200

 $Form.Text = ”Test”

 # Set the font of the text to be used within the form

 $Font = New-Object System.Drawing.Font("Times New Roman",12)

 $Form.Font = $Font

function Ausführen{

#Paint Ausführen

if($paintCheckBox.checked -eq $true) {mspaint.exe}

#NotePad Ausführen

if($DownloadsCheckBox.checked -eq $true) {Nodepad.exe}

}

 #Add an Ausführen button

 $AusführenButton = new-object System.Windows.Forms.Button

 $AusführenButton.Location = new-object System.Drawing.Size(30,30)

 $AusführenButton.Size = new-object System.Drawing.Size(100,40)

 $AusführenButton.Text = "Ausführen"

 $AusführenButton.Add_Click({(Ausführen)})

 $form.Controls.Add($AusführenButton)

 #Add a Exit button

 $ExitButton = new-object System.Windows.Forms.Button

 $ExitButton.Location = new-object System.Drawing.Size(160,30)

 $ExitButton.Size = new-object System.Drawing.Size(100,40)

 $ExitButton.Text = "Exit"

 $ExitButton.Add_Click({$Form.Close()})

 $form.Controls.Add($ExitButton)

 #Add a CheckBox  

 $paintCheckBox=New-Object System.Windows.Forms.CheckBox

 $paintCheckBox.Name="Paint"

 $paintCheckBox.Text="Paint"

 $paintCheckBox.TabIndex=0

 $paintCheckBox.Location=New-Object System.Drawing.Point(30,80)

 $paintCheckBox.Size = new-object System.Drawing.Size(200,40)

 $NotePadCheckBox=New-Object System.Windows.Forms.CheckBox

 $NotePadCheckBox.Name="NotePad"

 $NotePadCheckBox.Text="NotePad"

 $NotePadCheckBox.TabIndex=0

 $NotePadCheckBox.Location=New-Object System.Drawing.Point(30,110)

 $NotePadCheckBox.Size = new-object System.Drawing.Size(200,40)

 $paintCheckBox,$NotePadCheckBox | foreach {$Form.Controls.Add($_)}

  

 # Activate the form

 $Form.Add_Shown({$Form.Activate()})

 [void] $Form.ShowDialog()

}

#Call the function

Test

programmieren, PowerShell

Meistgelesene Beiträge zum Thema PowerShell