IngoB 0 Geschrieben 18. Dezember 2020 Melden Geschrieben 18. Dezember 2020 Hallo Ich bin noch bei den Basics von PS aber würde mir gern etwas kniffligeres anlernen. Derzeit habe ich folgendes vor: 1. Eine GUI mit 2 Dropdowns 2. Dropdown 1 hat 3 Wahlmöglichkeiten 3. Die Auswahl von Dropdown 1 soll als Variable gespeichert werden 4. Die Variable soll dann verwendet werden um eines von 3 möglichen Textfiles zu wählen. 5. Der Inhalt des gewählten textfiles will ich an Dropdown 2 übergeben. (liste von Ordnern) 6. Beide selektionen werden dann als variable zum ausführen eines Bat files übergeben als $1 und $2 Natürlich habe ich ein wenig herumprobiert, komme aber auf keinen grünen zweig.. Ich schaffe es nicht die hürde zu nehmen das txt file pervariable zu finden! [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.BackgroundImage = $objImage $objForm.BackgroundImageLayout = "Center" $objForm.Text = "Selektion" $objForm.Size = New-Object System.Drawing.Size(400,300) #BOX1 $DropDownBox = New-Object System.Windows.Forms.ComboBox $DropDownBox.Location = New-Object System.Drawing.Size(10,40) $DropDownBox.Size = New-Object System.Drawing.Size(260,20) $DropDownBox.DropDownHeight = 200 [void] $DropDownBox.Items.Add('CATIA') [void] $DropDownBox.Items.Add('UGS') [void] $DropDownBox.Items.Add('PTC') $objForm.Controls.Add($DropDownBox) #$DropDownBox.Add_SelectedIndexChanged({ $CADName = $DropDownBox.SelectedItem; }) [string]$CADName = $DropDownBox.SelectedItem $Button = New-Object System.Windows.Forms.Button $Button.Location = New-Object System.Drawing.Size(10,60) $Button.Size = New-Object System.Drawing.Size(120,23) $Button.Text = "Select CAD" $objForm.Controls.Add($Button) #Add Button event $Button.Add_Click( { #BOX2 Write-Host "CADName=$($CADName)" $label2 = New-Object System.Windows.Forms.Label $label2.Location = New-Object System.Drawing.Point(10,90) $label2.Size = New-Object System.Drawing.Size(280,20) $label2.Text = 'Database Name' $objform.Controls.Add($label2) $DropDownBox2 = New-Object System.Windows.Forms.ComboBox $DropDownBox2.Location = New-Object System.Drawing.Size(10,110) $DropDownBox2.Size = New-Object System.Drawing.Size(260,20) $DropDownBox2.DropDownHeight = 200 $objForm.Controls.Add($DropDownBox2) $cadlist = Get-Content -Path "C:\Users\u22u47\Desktop\$($CADName).txt" foreach ($cad in $cadlist) { $DropDownBox2.Items.Add($cad) } }) $objForm.ShowDialog()
BOfH_666 586 Geschrieben 18. Dezember 2020 Melden Geschrieben 18. Dezember 2020 Die Zuweisung ... [string]$CADName = $DropDownBox.SelectedItem ... muss in den Block für die $Button.Add_Click Aktion. Du willst ja die Variable erst zuweisen, wenn Du den Button klickst, oder? 1
IngoB 0 Geschrieben 21. Dezember 2020 Autor Melden Geschrieben 21. Dezember 2020 On 12/18/2020 at 4:53 PM, BOfH_666 said: Die Zuweisung ... [string]$CADName = $DropDownBox.SelectedItem ... muss in den Block für die $Button.Add_Click Aktion. Du willst ja die Variable erst zuweisen, wenn Du den Button klickst, oder? Ok danke....manchmal ist man offenbar einfach nur blind.... ;)
IngoB 0 Geschrieben 21. Dezember 2020 Autor Melden Geschrieben 21. Dezember 2020 [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $objForm = New-Object System.Windows.Forms.Form $objForm.BackgroundImageLayout = "Center" $objForm.Text = "Local Copy" $objForm.Size = New-Object System.Drawing.Size(400,400) #first DROPDOWN Box $label1 = New-Object System.Windows.Forms.Label $label1.Location = New-Object System.Drawing.Point(10,90) $label1.Size = New-Object System.Drawing.Size(120,20) $label1.Text = "CAD Vendor" $label1.Font = New-Object System.Drawing.Font("Arial",10) $label1.BackColor="Transparent" $objform.Controls.Add($label1) $DropDownBox = New-Object System.Windows.Forms.ComboBox $DropDownBox.Location = New-Object System.Drawing.Size(10,115) $DropDownBox.Size = New-Object System.Drawing.Size(100,20) $DropDownBox.DropDownHeight = 200 [void] $DropDownBox.Items.Add('CATIA') [void] $DropDownBox.Items.Add('UGS') [void] $DropDownBox.Items.Add('PTC') $objForm.Controls.Add($DropDownBox) $CADButton = New-Object System.Windows.Forms.Button $CADButton.Location = New-Object System.Drawing.Size(10,140) $CADButton.Size = New-Object System.Drawing.Size(120,25) $CADButton.Text = "Select CAD" $CADButton.BackColor="Black" $CADButton.ForeColor="White" $objForm.Controls.Add($CADButton) #Add Button event $CADButton.Add_Click( { [string]$global:CADName = $DropDownBox.SelectedItem #$global:CADName = $DropDownBox.SelectedItem.ToString() #second DROPDOWN Box $label2 = New-Object System.Windows.Forms.Label $label2.Location = New-Object System.Drawing.Point(10,190) $label2.Size = New-Object System.Drawing.Size(120,20) $label2.Text = "CAD Release" $label2.Font = New-Object System.Drawing.Font("Arial",10) $label2.BackColor="Transparent" $objform.Controls.Add($label2) if ($global:CADName) { $global:DropDownBox2 = New-Object System.Windows.Forms.ComboBox $global:DropDownBox2.Location = New-Object System.Drawing.Size(10,215) $global:DropDownBox2.Size = New-Object System.Drawing.Size(100,20) $global:DropDownBox2.DropDownHeight = 200 $rellist = Get-Content -Path "C:\Users\u22u47\Desktop\$($global:CADName).txt" foreach ($rel in $rellist) { $global:DropDownBox2.Items.Add($rel) } $objForm.Controls.Add($global:DropDownBox2) $RELButton = New-Object System.Windows.Forms.Button $RELButton.Location = New-Object System.Drawing.Size(10,240) $RELButton.Size = New-Object System.Drawing.Size(120,25) $RELButton.Text = "Select Release" $RELButton.BackColor="Black" $RELButton.ForeColor="White" $objForm.Controls.Add($RELButton) #Add Button event $RELButton.Add_Click( { [string]$global:RELName = $global:DropDownBox2.SelectedItem #$global:RELName = $global:DropDownBox2.SelectedItem.ToString() If ($global:DropDownBox2.SelectedItem -eq $null) { Write-Host "no selection" } }) } $label3 = New-Object System.Windows.Forms.Label $label3.Location = New-Object System.Drawing.Point(10,300) $label3.Size = New-Object System.Drawing.Size(120,20) $label3.Text = $global:CADName $label3.Font = New-Object System.Drawing.Font("Arial",10) $label3.BackColor="Transparent" $objform.Controls.Add($label3) $label4 = New-Object System.Windows.Forms.Label $label4.Location = New-Object System.Drawing.Point(10,400) $label4.Size = New-Object System.Drawing.Size(120,20) $label4.Text = $global:RELName $label4.Font = New-Object System.Drawing.Font("Arial",10) $label4.BackColor="Transparent" $objform.Controls.Add($label4) }) $objForm.ShowDialog() Irgendwie stehe ich mit meinem Wissen komplett an... Ich schaffe es nicht die beiden Variablen CADName und RELName auszugeben... habe mir ganz unten 2 zusätliche labels eingebaut um die selektion zu sehen.. Den CAD Name bekomme ich rein ins label 3 aber den REL Name nicht.. Ich bin mir sicher, dass mein aufbau komplett falsch ist.
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden