I'm working on a GUI that does some basic .csv editing, it utilizes a folderbrowserdialog prompt for the user to choose the directory in which the .csv editing takes place - currently this is all working, but I've found that trying to get the directory selected in the browser prompt isn't correctly being displayed on the GUI as a label. Instead the directory will only show when the script is run a second time - always showing the directory chosen from the previous run. How do I go about having a label that updates to display the chosen directory in the GUI? Currently cobbled together the following from previous searches:
$BrowseBtn.Add_Click({ Browse })
function Browse ($initialDirectory="")
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null
$foldername = New-Object System.Windows.Forms.FolderBrowserDialog
$foldername.Description = "Select a folder"
$foldername.rootfolder = "MyComputer"
$foldername.SelectedPath = $initialDirectory
if($foldername.ShowDialog() -eq "OK")
{
$folder += $foldername.SelectedPath
}
return $folder
}
$path=Browse
$Directory = New-Object system.Windows.Forms.Label
$Directory.text=$path
$Directory.AutoSize = $false
$Directory.width = 350
$Directory.height = 50
$Directory.location = New-Object System.Drawing.Point(20,220)
$Directory.Font = 'Microsoft Sans Serif,10'
Any feedback on this would be greatly appreciated.