Powershell - 如何调用具有多重选择的复选框窗口 [英] Powershell - How to invoke a checkbox windows with multiple choice
问题描述
我有一些方法来调用一个窗口与多个复选框。根据复选框,这将启用或禁用我的脚本的一部分。
我不知道如何创建形状以及如何在var中设置true / false值以启用或禁用我的脚本部分。 / p>
任何人都知道如何创建这种窗口复选框?
此代码(在 PrimalScript 的帮助下构建表单代码)有3个复选框。基于状态(选中或未选中),列表框将从某些命令的结果填充。
复制,粘贴并播放它。
function GenerateForm {
[reflection.assembly] :: loadwithpartialname(System.Windows.Forms )| Out-Null
[reflection.assembly] :: loadwithpartialname(System.Drawing)| Out-Null
$ form1 = New-Object System.Windows.Forms.Form
$ button1 = New-Object System.Windows.Forms.Button
$ listBox1 = New- Object System.Windows.Forms.ListBox
$ checkBox3 = New-Object System.Windows.Forms.CheckBox
$ checkBox2 = New-Object System.Windows.Forms.CheckBox
$ checkBox1 = New -Object System.Windows.Forms.CheckBox
$ InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$ b1 = $ false
$ b2 = $ false
$ b3 = $ false
#---------------------------------- ------------
#Generated事件脚本块
#------------------------ ----------------------
$ handler_button1_Click =
{
$ listBox1.Items.Clear() ;
if($ checkBox1.Checked){$ listBox1.Items.Add(Checkbox 1 is checked)}
if($ checkBox2.Checked){$ listBox1。 Items.Add(Checkbox 2 is checked)}
if($ checkBox3.Checked){$ listBox1.Items.Add(Checkbox 3 is checked)}
if(!$ checkBox1.Checked -and!$ checkBox2.Checked -and!$ checkBox3.Checked){$ listBox1.Items.Add(No CheckBox selected ....)}
}
$ OnLoadForm_StateCorrection =
{#更正表单的初始状态以防止.Net最大化形式问题
$ form1.WindowState = $ InitialFormWindowState
}
#----------------------------------------------
#region生成的表单代码
$ form1.Text =Primal Form
$ form1.Name =form1
$ form1.DataBindings.DefaultDataSourceUpdateMode = 0
$ System_Drawing_Size = New-Object System.Drawing.Size
$ System_Drawing_Size.Width = 450
$ System_Drawing_Size.Height = 236
$ form1.ClientSize = $ System_Drawing_Size
$ button1.TabIndex = 4
$ 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 =Run Script
$ System_Drawing_Point = New-Object System.Drawing.Point
$ System_Drawing_Point.X = 27
$ System_Drawing_Point.Y = 156
$ button1.Location = $ System_Drawing_Point
$ button1.DataBindings .DefaultDataSourceUpdateMode = 0
$ button1.add_Click($ handler_button1_Click)
$ form1.Controls.Add($ button1)
$ listBox1.FormattingEnabled = $ True
$ System_Drawing_Size = New-Object System.Drawing.Size
$ System_Drawing_Size.Width = 301
$ System_Drawing_Size.Height = 212
$ listBox1.Size = $ System_Drawing_Size
$ listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$ listBox1.Name =listBox1
$ System_Drawing_Point = New-Object System.Drawing.Point
$ System_Drawing_Point.X = 137
$ System_Drawing_Point .Y = 13
$ listBox1.Location = $ System_Drawing_Point
$ listBox1.TabIndex = 3
$ form1.Controls.Add($ listBox1)
$ checkBox3.UseVisualStyleBackColor = $ True
$ System_Drawing_Size = New-Object System.Drawing.Size
$ System_Drawing_Size.Width = 104
$ System_Drawing_Size.Height = 24
$ checkBox3.Size = $ System_Drawing_Size
$ checkBox3.TabIndex = 2
$ checkBox3.Text =CheckBox 3
$ System_Drawing_Point = New-Object System.Drawing.Point
$ System_Drawing_Point.X = 27
$ System_Drawing_Point.Y = 75
$ checkBox3.Location = $ System_Drawing_Point
$ checkBox3.DataBindings.DefaultDataSourceUpdateMode = 0
$ checkBox3.Name =checkBox3
$ form1.Controls.Add($ checkBox3)
$ checkBox2.UseVisualStyleBackColor = $ True
$ System_Drawing_Size = New-Object System。 Drawing.Size
$ System_Drawing_Size.Width = 104
$ System_Drawing_Size.Height = 24
$ checkBox2.Size = $ System_Drawing_Size
$ checkBox2.TabIndex = 1
$ checkBox2 .Text =CheckBox 2
$ System_Drawing_Point = New-Object System.Drawing.Point
$ System_Drawing_Point.X = 27
$ System_Drawing_Point.Y = 44
$ checkBox2.Location = $ System_Drawing_Point
$ checkBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$ checkBox2.Name =checkBox2
$ form1.Controls.Add($ checkBox2)
$ checkBox1.UseVisualStyleBackColor = $ True
$ System_Drawing_Size = New-Object System.Drawing.Size
$ System_Drawing_Size.Width = 104
$ System_Drawing_Size。 Height = 24
$ checkBox1.Size = $ System_Drawing_Size
$ checkBox1.TabIndex = 0
$ checkBox1.Text =CheckBox 1
$ System_Drawing_Point = New-Object System.Drawing .Point
$ System_Drawing_Point.X = 27
$ System_Drawing_Point.Y = 13
$ checkBox1.Location = $ System_Drawing_Point
$ checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$ checkBox1.Name =checkBox1
$ form1.Controls.Add($ checkBox1)
#保存表单的初始状态
$ InitialFormWindowState = $ form1.WindowState
#Init OnLoad事件来更正窗体的初始状态
$ form1.add_Load($ OnLoadForm_StateCorrection)
#显示窗体
$ form1。 ShowDialog()| Out-Null
} #End函数
#Call函数
GenerateForm
I've seach some way to invoke a windows with many checkbox. Depending on the checkbox checked, that will enable or disable so part of my script.
I don't have any idea how to create the shape and how to set a "true/false" value in var to enable or disable portion of my script.
Anyone know how to create that kind of windows checkbox ?
This code ( made with the help of PrimalScript for building form code ) has 3 checkbox. Based on the status (checked or not) the listbox will be populated from the result of some commands. Copy, paste and play with it.
function GenerateForm {
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$listBox1 = New-Object System.Windows.Forms.ListBox
$checkBox3 = New-Object System.Windows.Forms.CheckBox
$checkBox2 = New-Object System.Windows.Forms.CheckBox
$checkBox1 = New-Object System.Windows.Forms.CheckBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$b1= $false
$b2= $false
$b3= $false
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
$handler_button1_Click=
{
$listBox1.Items.Clear();
if ($checkBox1.Checked) { $listBox1.Items.Add( "Checkbox 1 is checked" ) }
if ($checkBox2.Checked) { $listBox1.Items.Add( "Checkbox 2 is checked" ) }
if ($checkBox3.Checked) { $listBox1.Items.Add( "Checkbox 3 is checked" ) }
if ( !$checkBox1.Checked -and !$checkBox2.Checked -and !$checkBox3.Checked ) { $listBox1.Items.Add("No CheckBox selected....")}
}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$form1.Text = "Primal Form"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 450
$System_Drawing_Size.Height = 236
$form1.ClientSize = $System_Drawing_Size
$button1.TabIndex = 4
$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 = "Run Script"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 156
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($handler_button1_Click)
$form1.Controls.Add($button1)
$listBox1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 301
$System_Drawing_Size.Height = 212
$listBox1.Size = $System_Drawing_Size
$listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox1.Name = "listBox1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 137
$System_Drawing_Point.Y = 13
$listBox1.Location = $System_Drawing_Point
$listBox1.TabIndex = 3
$form1.Controls.Add($listBox1)
$checkBox3.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 24
$checkBox3.Size = $System_Drawing_Size
$checkBox3.TabIndex = 2
$checkBox3.Text = "CheckBox 3"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 75
$checkBox3.Location = $System_Drawing_Point
$checkBox3.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox3.Name = "checkBox3"
$form1.Controls.Add($checkBox3)
$checkBox2.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 24
$checkBox2.Size = $System_Drawing_Size
$checkBox2.TabIndex = 1
$checkBox2.Text = "CheckBox 2"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 44
$checkBox2.Location = $System_Drawing_Point
$checkBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox2.Name = "checkBox2"
$form1.Controls.Add($checkBox2)
$checkBox1.UseVisualStyleBackColor = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 104
$System_Drawing_Size.Height = 24
$checkBox1.Size = $System_Drawing_Size
$checkBox1.TabIndex = 0
$checkBox1.Text = "CheckBox 1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 27
$System_Drawing_Point.Y = 13
$checkBox1.Location = $System_Drawing_Point
$checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$checkBox1.Name = "checkBox1"
$form1.Controls.Add($checkBox1)
#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 Function
#Call the Function
GenerateForm
这篇关于Powershell - 如何调用具有多重选择的复选框窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!