C# TableLayoutPanel 替换控件?
我想知道是否可以在运行时将 TableLayoutPanel 中的一个控件替换为另一个控件。我有一个组合框和一个按钮,它们在运行时动态添加到 TableLayoutPanel 中,当用户在组合框中选择一个项目并单击按钮时,我想用包含文本的标签替换组合框选定的组合框项目。
基本上,如果我可以简单地删除控件并在其索引处插入另一个控件,那么这对我有用。但是,我在 TableLayoutPanel 的 Controls 集合上没有看到像“splice”或“insert”这样的选项,我想知道是否有一种简单的方法可以在特定索引处插入控件。提前致谢。
I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过使用我想要交换的两个控件填充面板并将其放入 TableLayoutPanel 中来修复此问题。然后我根据我想在什么时间看到它们来设置它们的可见性。
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
这就是我能够想出的满足我需要的东西。它获取 ComboBox 的位置并使用所选值创建新标签。
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.