$form1 = New-Object System.Windows.Forms.Form
$button_cancel = New-Object System.Windows.Forms.Button
$menulist = New-Object System.Windows.Forms.CheckedListBox
$button_remove = New-Object System.Windows.Forms.Button
$button_add = New-Object System.Windows.Forms.Button
$button_open = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
$button_add_OnClick = {
#TODO: Place custom script here
}
$OnLoadForm_StateCorrection = {
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
#----------------------------------------------
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 402
$System_Drawing_Size.Width = 340
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = "form1"
$form1.Text = "Office-Vorlagen Menu"
$form1.add_Load($handler_form1_Load)
$button_cancel.DataBindings.DefaultDataSourceUpdateMode = 0
$menulist.DataBindings.DefaultDataSourceUpdateMode = 0
$menulist.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 24
$menulist.Location = $System_Drawing_Point
$menulist.Name = "menulist"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 328
$System_Drawing_Size.Width = 235
#Speichert den Pfad in die Variable -Leaf zeigt nur den Dateinamen an und -Resolve referenziert auf den Pfad
$template1 = Split-Path C:\Users\$Env:USERNAME\Documents\test.txt -Leaf -Resolve
$template2 = Split-Path C:\Users\$Env:USERNAME\Documents\test2.txt -Leaf -Resolve
$TemplateArray = $template1,$template2;
$menulist.Items.AddRange($TemplateArray)
$menulist.CheckedItems
$menulist.Size = $System_Drawing_Size
$menulist.TabIndex = 7
$form1.Controls.Add($menulist)
$button_remove.DataBindings.DefaultDataSourceUpdateMode = 0
$button_add.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 253
$System_Drawing_Point.Y = 154
$button_add.Location = $System_Drawing_Point
$button_add.Name = "button_add"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 75
$button_add.Size = $System_Drawing_Size
$button_add.TabIndex = 2
$button_add.Text = "Add"
$button_add.UseVisualStyleBackColor = $True
$button_add.add_Click($button_add_OnClick)
$form1.Controls.Add($button_add)
#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 Function
#Call the Function
GenerateForm
基本上,我希望能够使用Add
按钮向我的CheckList
添加新元素,我计划使用FolderBrowserDialog
执行此任务。我的问题是$TemplateArray
是静态的,这意味着一旦我更改它(例如删除$template1
),列表就会完全停止读取数组。
Add
按钮应该能够创建新的数组,然后以某种方式将其放入列表中。