Function Show-WinForm([Array]$objectArray){
#$objectArray = @($input)
#Ensure that they've piped information into the script
if($objectArray.Count -eq 0 )
{
Write-Error "This script requires pipeline input." ;
return
}
#load the windows Forms assembly
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");
##Create the main form
$form = New-Object Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size @(600,600);
#Create the listBox to hold the items form the pipeline
$listbox = New-Object System.Windows.Forms.CheckedListBox;
$listbox.CheckOnClick = $true
$listbox.Dock = 'Fill' ;
$form.Text = "Select the list of objects you wish to pass down the pipeline"
$listbox.Items.AddRange($objectArray);
#Create the button panel to hold the ok and cancel buttons
$buttonPanel = New-Object Windows.Forms.Panel ;
$buttonPanel.Size = New-Object System.Drawing.Size @(600,300);
$buttonPanel.Dock = "Bottom";
#Crate the cancel button ,which will anchor to the bottom right
$cancleButton = New-Object Windows.Forms.Button
$cancleButton.Text = "Cancel" ;
$cancleButton.DialogResult = "Cancel"
$cancleButton.Top = $buttonPanel.Height - $cancleButton.Height - 5;
$cancleButton.Left = $buttonPanel.Width - $cancleButton.Width - 10;
$cancleButton.Anchor = 'Right' ;
#Create the ok button, which will anchor to the left of cancel
$okButton = New-Object windows.Forms.Button ;
$okButton.Text = "OK"
$okButton.DialogResult = "OK" ;
$okButton.Top = $cancleButton.Top ;
$okButton.Left = $cancleButton.Left - $okButton.Width - 5;
$okButton.Anchor = 'Right' ;
#Add the buttons to the button panel
$buttonPanel.Controls.Add($okButton);
$buttonPanel.Controls.Add($cancleButton);
#add the button panel and list box to the form and also set the actions for the buttons
$form.Controls.Add($listbox);
$form.Controls.Add($buttonPanel);
$form.AcceptButton = $okButton ;
$form.CancelButton = $cancleButton ;
$form.add_Shown({ $form.Activate() });
#show the form and wait for the response
$result = $form.ShowDialog();
#if the pressed oj or enter go through all the checked items and send the corresponding object down the pipeline
if($result -eq "OK")
{
foreach($index in $listbox.CheckedIndices)
{
$objectArray[$index] ;
}
}
}
分享到:
相关推荐
在C#编程中,删除文件夹下的所有子...WinForm应用程序通常更倾向于使用`Directory`或`FileSystemWatcher`,而DOS环境下则更适合使用PowerShell或CMD命令。在实际开发中,要确保处理异常情况,避免不必要的数据丢失。
IIS是微软提供的一个强大的Web服务器,用于托管Web应用程序和服务。 首先,我们要理解C#如何执行操作系统级别的操作。这通常通过使用.NET框架中的System.Management.Automation命名空间来实现,该命名空间提供了对...
在C#编程环境中,WinForm(Windows Forms)是一种常见的用于构建桌面应用程序的用户界面框架。在本场景中,我们探讨的是如何在C# WinForm应用中解析JSON数据,并将其显示在DataGridView控件中。JSON(JavaScript ...
4. 构建和部署脚本:可能包含批处理文件或PowerShell脚本,用于编译、测试和部署应用程序。 5. 示例或测试程序:可能有一个简单的示例应用程序,展示了Aero效果的实际运行情况。 实现Aero特效的关键技术可能涉及...
这里我们可以创建一个名为"logrotate.winform"的程序或者脚本来实现这一目的。 1. **日志文件轮换**:日志文件轮换是指当日志文件达到一定大小或者时间间隔时,创建一个新的日志文件继续记录,旧的日志文件则被保存...
1. **创建WinForm项目**:打开Visual Studio,新建一个C# Windows Forms Application项目。 2. **添加控件**:在设计界面中,添加必要的控件,如按钮(Button)和文本框(TextBox),用于触发命令行调用和显示结果...
`Asp.net`是由微软开发的一种用于构建动态网站、Web应用程序和Web服务的框架。它提供了丰富的特性和工具,如ASP.NET MVC、Web Forms、Web API等,帮助开发者快速构建高性能的Web应用。`Asp.net`的应用程序通常由一...
在IT行业中,C#是一种广泛使用的编程语言,特别是在Windows应用程序开发中,比如WinForms应用。而VBScript(Visual Basic Script)则是一种轻量级的脚本语言,常用于自动化任务和与Windows操作系统交互。当我们需要...