Powershell GUI返回文件路径
这将写出ListViewItem:{test} 我需要path2作为我选择的文件夹的文件路径Powershell GUI返回文件路径,powershell,user-interface,Powershell,User Interface,这将写出ListViewItem:{test} 我需要path2作为我选择的文件夹的文件路径 我已经编写了一个gui windows资源管理器,这样我可以搜索文件和文件夹。按钮3是选择。此按钮应获取所选内容的值并将其分配给path2,然后关闭gui。然而,我很难意识到这一点。如果您更改脚本行,则可以编写所选的foldername,我们将非常感谢您提供的任何帮助 从 到 美好的多谢了,真是妙不可言。您介意解释一下$script:before path2的作用吗?它在脚本级别设置变量。如果您不使用它
我已经编写了一个gui windows资源管理器,这样我可以搜索文件和文件夹。按钮3是选择。此按钮应获取所选内容的值并将其分配给path2,然后关闭gui。然而,我很难意识到这一点。如果您更改脚本行,则可以编写所选的foldername,我们将非常感谢您提供的任何帮助 从 到
美好的多谢了,真是妙不可言。您介意解释一下$script:before path2的作用吗?它在脚本级别设置变量。如果您不使用它,$path2将在您退出该函数后立即消失。
cls
function GenerateForm2 {
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$button2 = New-Object System.Windows.Forms.Button
$button1 = New-Object System.Windows.Forms.Button
$button3 = New-Object System.Windows.Forms.Button
$button4 = New-Object System.Windows.Forms.Button
$listView1 = New-Object System.Windows.Forms.ListView
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#region ImageList for nodes
$global:imageList = new-Object System.Windows.Forms.ImageList
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 32
$System_Drawing_Size.Height = 32
$global:imageList.ImageSize = $System_Drawing_Size
$image1 = [System.Drawing.Image]::FromFile("M:\Powershell\ico files\folder.ico")
$image2 = [System.Drawing.Image]::FromFile("M:\Powershell\ico files\file.ico")
$global:imageList.Images.Add("folder",$image1)
$global:imageList.Images.Add("file",$image2)
#endregion
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$button1_OnClick=
{
if ($script:previousItem) {
Refresh-ListView $script:previousItem
} else {
[System.Windows.Forms.MessageBox]::Show("Nothing to go back")
}
}
$doubleClick=
{
if ($listView1.SelectedItems[0].tag -eq "File") {
[System.Windows.Forms.MessageBox]::Show("You double clicked a file")
} else {
Refresh-ListView $listView1.SelectedItems[0].Name
}
}
$button2_OnClick=
{
$form1.Close()
}
$OnLoadForm_StateCorrection=
{
$form1.WindowState = $InitialFormWindowState
$listView1.LargeImageList = $imageList
Refresh-ListView "c:\"
}
$button3_OnClick=
{
if($listView1.SelectedItems[0].tag -eq "Folder"){
$path2 = $listView1.SelectedItems[0]
$form1.Close()
}
}
$button4_OnClick=
{
$pathNew = CustomInputBox
if(Test-Path $pathNew){
echo("Folder Already Exists")
}
else
{
New-Item -ItemType Directory -path $pathNew -Force
echo("Folder created")
}
$path2 = $pathNew
$form1.Close()
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Windows Browser"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 689
$System_Drawing_Size.Height = 499
$form1.ClientSize = $System_Drawing_Size
$button2.TabIndex = 2
$button2.Name = "button2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button2.Size = $System_Drawing_Size
$button2.UseVisualStyleBackColor = $True
$button2.Text = "Close"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 602
$System_Drawing_Point.Y = 459
$button2.Location = $System_Drawing_Point
$button2.DataBindings.DefaultDataSourceUpdateMode = 0
$button2.add_Click($button2_OnClick)
$form1.Controls.Add($button2)
$button1.TabIndex = 1
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = "Back"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 459
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($button1_OnClick)
$form1.Controls.Add($button1)
$button3.TabIndex = 3
$button3.Name = "button3"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button3.Size = $System_Drawing_Size
$button3.UseVisualStyleBackColor = $true
$button3.Text = "Choose"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 200
$System_Drawing_Point.Y = 459
$button3.Location = $System_Drawing_Point
$button3.DataBindings.DefaultDataSourceUpdateMode =0
$button3.add_Click($button3_OnClick)
$form1.Controls.Add($button3)
$button4.TabIndex = 4
$button4.Name = "button4"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 75
$System_Drawing_Size.Height = 23
$button4.Size = $System_Drawing_Size
$button4.UseVisualStyleBackColor = $true
$button4.Text = "Create"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 400
$System_Drawing_Point.Y = 459
$button4.Location = $System_Drawing_Point
$button4.DataBindings.DefaultDataSourceUpdateMode = 0
$button4.add_Click($button4_OnClick)
$form1.Controls.Add($button4)
$listView1.UseCompatibleStateImageBehavior = $False
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 664
$System_Drawing_Size.Height = 440
$listView1.Size = $System_Drawing_Size
$listView1.DataBindings.DefaultDataSourceUpdateMode = 0
$listView1.Name = "listView1"
$listView1.View = 0
$listView1.TabIndex = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 13
$listView1.Location = $System_Drawing_Point
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 32
$System_Drawing_Size.Height = 32
$listView1.TileSize = $System_Drawing_Size
$listView1.add_DoubleClick($doubleClick)
$form1.Controls.Add($listView1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function2
GenerateForm2
Write-Host $path2
$path2 = $listView1.SelectedItems[0]
$Script:path2 = $listView1.SelectedItems[0].Name.ToString()