显示控件的集合在Windows窗体 [英] Displaying a collection of controls in Windows Forms
问题描述
我要显示类似以下内容: -
I want to display something like the following :-
每行大约一个过程(信息,如PID,家长等)。用户可以检查复选框
,然后单击启动按钮,获取有关该过程的一些动态信息。
Each row is about a process (information like PID, Parent etc.). User can check the checkbox
and click Launch button to get some dynamic details about that process.
问题是,的CheckedListBox
控件不允许多个列和其他控件像的ListView
(允许多列)不允许像 CheckBox控件
被嵌入在列。
The problem is that CheckedListBox
control doesn't allow more than one columns and other controls like ListView
(which allow multiple columns) don't allow controls like checkbox
to be embedded in a columns.
我想知道是否有一个控制,这将让我有自定义控件一个列表,其中每个自定义控件包含复选框
,某些文本
和一些动态文本
。
I want to know if there is a control which will allow me to have a list of custom controls where each custom control contains a checkbox
, Some Text
and Some Dynamic Text
.
这怎么能在Windows窗体中实现? 。在此先感谢
How can this be achieved in Windows Forms? Thanks in advance.
推荐答案
有您可以使用许多选项:
There are many options you can use:
- 您可以使用DataGridView中显示多列
- 使用
面板
或FlowLayoutPanel的
承载用户控件
这是 - 使用TableLayoutPanel中的
包含您的组件。
主机
- You can use DataGridView to show multiple columns
- use
Panel
orFlowLayoutPanel
that hosts aUserControl
that hosts that - use TableLayoutPanel contains your components.
例1:结果
。如果你想显示复选框
,文本框
,组合框
,按钮
,图片
,链接
您可以简单地使用 DataGridView的
。
Example 1:
If you want to show CheckBox
, TextBox
, ComboBox
, Button
, Image
, Link
you can simply use DataGridView
.
电网与 RowHeaderVisible
和 ColumnHeaderVisible
设置为假
示例2:
如果你需要自定义控制,以承载更多的复杂的控制或有对组件的更多控制,您可以创建一个用户控件
托管组件,然后:
If you need custom control to host more complicated controls or having more control on components, you can create a UserControl
hosting your components, then:
- 如果您只想自上而下流动,使用
面板
和用户控件与控件的属性Top添加到它
。 - 如果您可能要流以外自上而下的使用
FlowLayoutPanel的
补充的情况下,您的控制它。
- If you only want top-down flow, Use a
Panel
and add your user control to it withDock
property of control set toTop
. - If you may want flows other than top-down Use a
FlowLayoutPanel
to add instances of your control to it.
创建一个用户控件
添加它的实例到你的面板
或 FlowLayoutPanel的
Add instances of it to your Panel
or FlowLayoutPanel
这篇关于显示控件的集合在Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!