几何尺寸与公差论坛

 找回密码
 注册
查看: 72|回复: 2

矩阵表的行和列是对称分布的,列数可能是n个,用winform如何编写?

  [复制链接]
发表于 2024-7-11 16:46:42 | 显示全部楼层 |阅读模式
https://www.cnblogs.com/swjian/p/9815155.html
winform用 tablayoutpanel
C# TableLayoutPanel使用方法
一、利用TableLayoutPanel类展示表格,以10行5列为例

第1步:在前台创建一个panel,使TableLayoutPanel对象填充其内部。

第2步:创建TableLayoutPanel类,其实例对象名为table

TableLayoutPanel table = new TableLayoutPanel();
第3步:设置列样式,循环显示行

复制代码
private void Form2_Load(object sender, EventArgs e)
{
    // 默认添加一行数据
    table.Dock = DockStyle.Top;     //顶部填充
    panel1.Controls.Add(table);     
    table.ColumnCount = 5;          //5列
    table.Height = table.RowCount * 40; //table的整体高度,每行40

    table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, table.Width * 0.2f));    //利用百分比计算,0.2f表示占用本行长度的20%
    table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, table.Width * 0.2f));
    table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, table.Width * 0.2f));
    table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, table.Width * 0.2f));
    table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, table.Width * 0.2f));

    for (int i = 1; i <= 10; i++)
    {
        AddRow("苹果"+i.ToString().PadLeft(2,'0'),"橘子" + i.ToString().PadLeft(2, '0'), "香蕉" + i.ToString().PadLeft(2, '0'), "香瓜" + i.ToString().PadLeft(2, '0'), "甘蔗" + i.ToString().PadLeft(2, '0'));
   
 楼主| 发表于 2024-7-11 16:48:03 | 显示全部楼层
https://cloud.tencent.com/developer/article/2366267
【愚公系列】2023年11月 Winform控件专题 TableLayoutPanel控件详解
 楼主| 发表于 2024-7-11 16:48:12 | 显示全部楼层
或者用datagrid view控件
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-9-8 07:11 , Processed in 0.040566 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表