Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

FRAGE: Powershell GUI Auswahl aus Explorer und Übergabe des Wertes an ein Label Feld

$
0
0

Hallo Powershell Forum,

ich mache gerade meine ersten Gehversuche eine GUI in Powershell zu erstellen. Ich möchte in dem beigefügtem Script eine CSV-Datei aus dem Explorer auswählen und in ein Labelfeld schreiben. Diese Variable möchte ich später weiterverwenden. Die Oberfläche konnte ich umsetzten. Ebenso den Explorer Aufruf. Jedoch weiß ich nicht wie ich den Dateinamen mit Pfad in das Label Feld schreibe.

Kann mich hierbei jemand unterstützen?

    
Add-Type -AssemblyName System.Drawing


# -----------------------------------------------------------------------------------------
# Function
# -----------------------------------------------------------------------------------------


    Function fun_import_csv_path ()    {        $import_csv_path = New-Object System.Windows.Forms.OpenFileDialog -Property @{        InitialDirectory = [Environment]::GetFolderPath('Desktop')        Filter = 'SpreadSheet (*.xlsx)|*.xlsx'        }    $null = $import_csv_path.ShowDialog()    $import_csv = $import_csv_path.FileName    write-host $import_csv    return $import_csv    }


# -----------------------------------------------------------------------------------------
# Generate Formular
# -----------------------------------------------------------------------------------------
Function Generate-Form {
       <#    Generate Formular    #>    $Form = New-Object system.Windows.Forms.Form    $Form.Size = '640,270'    $Form.text = "Test Formular"    $Form.TopMost  = $false


# -----------------------------------------------------------------------------------------
# Add import-csv Textbox
# -----------------------------------------------------------------------------------------
    $txt_import_csv_file             = New-Object system.Windows.Forms.TextBox    $txt_import_csv_file.multiline   = $false    $txt_import_csv_file.text        = "Import CSV:"    $txt_import_csv_file.width       = 150    $txt_import_csv_file.height      = 20    $txt_import_csv_file.location    = New-Object System.Drawing.Point(20,80)    $txt_import_csv_file.Font        = 'Courier New,10'    $Form.Controls.Add($txt_import_csv_file)

# -----------------------------------------------------------------------------------------
# Add import-csv Label
# -----------------------------------------------------------------------------------------
    $lbl_import_csv                  = New-Object system.Windows.Forms.Label    $lbl_import_csv.text             = "C:\temp\test.csv"    $lbl_import_csv.BackColor        = "#ffffff"    $lbl_import_csv.AutoSize         = $false    $lbl_import_csv.width            = 300    $lbl_import_csv.height           = 20    $lbl_import_csv.location         = New-Object System.Drawing.Point(200,80)    $lbl_import_csv.Font             = 'Courier New,10'    $Form.Controls.Add($lbl_import_csv)


# -----------------------------------------------------------------------------------------
# Add import-csv Button
# -----------------------------------------------------------------------------------------
    $but_import_csv                  = New-Object system.Windows.Forms.Button    $but_import_csv.BackColor        = "#ffffff"    $but_import_csv.text             = "Select"    $but_import_csv.width            = 80    $but_import_csv.height           = 20    $but_import_csv.location         = New-Object System.Drawing.Point(530,80)    $but_import_csv.Font             = 'Courier New,10,style=Bold,Underline'    $but_import_csv.ForeColor        = "#000000"    $Form.Controls.Add($but_import_csv)    $but_import_csv.add_MouseClick({$txt_import_csv_file = fun_import_csv_path})


# -----------------------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------------------

         #Show the Form     $form.ShowDialog()| Out-Null  } #End Function  #Call the Function 
Generate-Form



Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>