在 Powershell 中创建 .NET 4 (WinForms) 动态表单控件 [英] .NET 4 (WinForms) Dynamic Form Control Creation in Powershell
问题描述
我正在尝试将表单控件动态添加到我在 PowerShell 中开发的 gui.我查看了 VB 和 C# 示例,但似乎无法让我的表单使用新控件实际填充 gui.我想要的是能够将大量潜在的附加控件附加到表单中,并将添加的控件转储到可滚动字段中,这样它们就不会在 gui 的末尾结束.我如何尝试完成此操作是将组合框附加到 tablelayoutpanel.我的想法是,使用新的组合框控件向 tablelayoutpanel 添加新行可以实现这一点.所以我想我有两个问题:
I am trying to dynamically add form controls to a gui I'm developing in PowerShell. I have looked at VB and C# examples but can't seem to get my form to actually populate the gui with a new control. What I want is to be able to append a potentially large number of additional controls to the form and the added controls get dumped into a scrollable field so they don't end up off the end of the gui. How I tried to accomplish this is append a combobox to a tablelayoutpanel. My idea being, adding a new row to the tablelayoutpanel with a new combobox control would accomplish this. So I suppose I have two questions:
- 这是将控件动态添加到允许可滚动溢出的对象的逻辑正确方法吗?
- 如果 #1 为真,我该如何完成这个任务?
这是我最近一次尝试的迭代:
This is the most recent iteration of my attempts:
$button1_Click={
$new = New-Object System.Windows.Forms.ComboBox
Add-ComboBox $rowCount
$rowCount++
}
function Add-ComboBox {
param([string] $rowCount)
$combobox = New-Object System.Windows.Forms.ComboBox
$combobox.Dock = [System.Windows.Forms.DockStyle]::Fill
$combobox.Text = ""
$combobox.Tag = "ComboBox$rowCount"
$tablelayoutpanel1.Controls.Add($combobox, 1, $rowCount)
}
非常感谢您的帮助.
推荐答案
我在 Microsoft Technet 论坛上找到了答案.论坛版主一直在帮助我解决这个问题.不过还是谢谢!
I found the answer on the Microsoft Technet forums. A forum moderator has been helping me out with this. Thanks though!
http:///social.technet.microsoft.com/Forums/en-US/ITCG/thread/b2c8abeb-3ae6-4936-9bef-a50a79fdff45/
这篇关于在 Powershell 中创建 .NET 4 (WinForms) 动态表单控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!