动态运行时将控件添加到TableLayoutPanel中

编程入门 行业动态 更新时间:2024-10-23 08:28:56
本文介绍了动态运行时将控件添加到TableLayoutPanel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个TableLayoutPanel开始两列0行。我需要做的是,动态添加行和填充都与不同的控件(这将是面板)列。在Form1我创建了TableLayout是这样的:

I have a TableLayoutPanel starting with two columns and 0 rows. What I need to do is, dynamically adding a row and filling both of the columns with different controls (it will be panels). In Form1 I am creating the TableLayout this way:

TableLayoutPanel Table = new TableLayoutPanel(); Table.Location = new Point(10, 40); Table.Size = new Size(620,100); Table.AutoSize = true; Table.Name = "Desk"; Table.ColumnCount = 2; Table.RowCount = 0; Table.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; Table.GrowStyle = System.Windows.Forms.TableLayoutPanelGrowStyle.AddRows; this.Controls.Add(Table);

之后运行期间我得到我有多少行需要,如果他们将充满要么Panel或一些标签。它可能发生在同一行左边将是面板,右侧标签等。

afterwards during runtime I am getting how many rows will I need, and if they will be filled with either a Panel or some Label. It might happen that in the same row left will be Panel, right Label etc..

推荐答案

使用像这样的:

Table.Controls.Add(new Label() { Text = "Type:", Anchor = AnchorStyles.Left, AutoSize = true }, 0, 0); Table.Controls.Add(new ComboBox() { Dock = DockStyle.Fill }, 0, 1);

您并不需要定义行数和列数,它们将被自动添加。

You don't need to define number of rows and columns, they will be added automatically.

更多推荐

动态运行时将控件添加到TableLayoutPanel中

本文发布于:2023-11-06 13:39:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   时将   动态   TableLayoutPanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!