C# winodw TableLayoutPanel 料盒生产状态UI自动生成

料盒生产状态UI自动生成,效果如下

以前公司项目的这些都是手动拖控件做的。每个设备的料盒数量不一样,层数不一样时都要发好几个小时去改相关细节和代码。上次改了一次。这个又来了。上次就有想法做成根据参数自动生成。但项目时间有限有没有去深入思路和深度。这次发了几个小时加班完成了。

代码:

复制代码
/// <summary>
        /// 表头的全选 复选框
        /// </summary>
        List<CheckBox> checkBoxAllList = new List<CheckBox>();

        /// <summary>
        /// 芯片生产状态标签
        /// </summary>
        Label[,] boxMarkContent = new Label[8, 25];//[料盒数量,料盒层数]

        /// <summary>
        /// 芯片选中列表
        /// [料盒索引,层索引]
        /// </summary>
        CheckBox[,] boxChipCheckArray = new CheckBox[3, 25];//[料盒数量,料盒层数]

/// <summary>
        /// 初始化 料盒UI
        /// </summary>
        private void initBoxUI()
        {
            //料盒索引
            int nBoxIndex = 0;
            //芯片层 索引
            int nChipIndex = 0;

            //AxisTestForm.BOX_COUNT 料盒数量
            this.tableLayoutPanel2.Controls.Clear();
            this.tableLayoutPanel2.ColumnStyles.Clear();//清除默认样式 这个很重要
            this.tableLayoutPanel2.RowStyles.Clear();//清除默认样式 这个很重要

            this.tableLayoutPanel2.Size = new Size(344, 651);
            this.tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 27F));

            this.tableLayoutPanel2.ColumnCount = 1 + AxisTestForm.BOX_COUNT * 2;
            this.tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 35F));
            //列宽
            double columnWidth = 100.0 / AxisTestForm.BOX_COUNT;
            //列索引
            int columnIndex = 0;
            //添加列
            for (int i = 0; i < AxisTestForm.BOX_COUNT; i++)
            {
                columnIndex++;
                this.tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, (float)columnWidth));
                this.tableLayoutPanel2.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 30F));

                Label labelTitle = new Label();
                labelTitle.Anchor = AnchorStyles.Bottom;
                labelTitle.Margin = new Padding(4, 0, 4, 0);
                labelTitle.Name = "lblBoxTitle" + i;
                //labelTitle.TabIndex = 1;
                labelTitle.Text = "料盒" + (i + 1);
                labelTitle.TextAlign = ContentAlignment.MiddleCenter;

                this.tableLayoutPanel2.Controls.Add(labelTitle, columnIndex, 0);

                columnIndex++;

                CheckBox checkBoxAll = new CheckBox();
                checkBoxAll.Anchor = AnchorStyles.Left;
                checkBoxAll.AutoSize = true;
                checkBoxAll.Checked = true;
                checkBoxAll.CheckState = CheckState.Checked;
                checkBoxAll.Name = "checkBoxAll" + i;
                checkBoxAll.Tag = i;
                checkBoxAll.Size = new Size(24, 21);
                //checkBoxAll.TabIndex = 3;
                checkBoxAll.Text = " ";
                checkBoxAll.UseVisualStyleBackColor = true;
                checkBoxAll.CheckedChanged += new System.EventHandler(this.checkBoxAll_CheckedChanged);

                this.tableLayoutPanel2.Controls.Add(checkBoxAll, columnIndex, 0);
                checkBoxAllList.Add(checkBoxAll);
            }
            //行索引
            int rowIndex = 1;
            //行高
            double rowHeight = 100.0 / AxisTestForm.BOX_CHIPSCOUNT;
            //添加行
            for (int layerIndex = AxisTestForm.BOX_CHIPSCOUNT; layerIndex > 0; layerIndex--)
            {
                columnIndex = 0;
                this.tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Percent, (float)rowHeight));
                if (layerIndex % 5 == 0)
                {
                    Label labelItemNo = new Label();
                    labelItemNo.AutoSize = true;
                    labelItemNo.BackColor = SystemColors.Control;
                    labelItemNo.Dock = DockStyle.Fill;
                    labelItemNo.Font = new Font("宋体", 10.5F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
                    labelItemNo.Margin = new Padding(4, 1, 4, 1);
                    labelItemNo.Name = "label_"+ layerIndex;
                    labelItemNo.Size = new Size(27, 18);
                    //labelItemNo.TabIndex = 4;
                    labelItemNo.Text = layerIndex.ToString();
                    labelItemNo.TextAlign = ContentAlignment.MiddleCenter;
                    this.tableLayoutPanel2.Controls.Add(labelItemNo, 0, rowIndex);
                }
                nChipIndex = layerIndex - 1;
                columnIndex++;
                //根据料盒数量生成对应列
                for (int i = 0; i < AxisTestForm.BOX_COUNT; i++)
                {
                    Label labelItem = new Label();
                    labelItem.AutoSize = true;
                    labelItem.BackColor = SystemColors.ActiveCaptionText;
                    labelItem.Dock = DockStyle.Fill;
                    labelItem.Margin = new Padding(4, 1, 4, 1);
                    labelItem.Name = "labelItem_" + i + "_" + nChipIndex;
                    //labelItem.TabIndex = 2;
                    labelItem.TextAlign = ContentAlignment.MiddleCenter;
                    this.tableLayoutPanel2.Controls.Add(labelItem, columnIndex, rowIndex);
                    nBoxIndex = i;
                    //芯片生产状态标签对象
                    boxMarkContent[nBoxIndex, nChipIndex] = labelItem;

                    columnIndex++;

                    CheckBox checkBoxItem = new CheckBox();
                    checkBoxItem.Anchor = AnchorStyles.Left;
                    checkBoxItem.AutoSize = true;
                    checkBoxItem.Checked = true;
                    checkBoxItem.CheckState = CheckState.Checked;
                    checkBoxItem.Name = "checkBox" + i + "_" + nChipIndex;
                    checkBoxItem.Size = new Size(24, 14);
                    //checkBoxItem.TabIndex = 3;
                    checkBoxItem.Text = " ";
                    checkBoxItem.UseVisualStyleBackColor = true;
                    checkBoxItem.Enabled = false;
                    this.tableLayoutPanel2.Controls.Add(checkBoxItem, columnIndex, rowIndex);
                    //芯片选中列表
                    boxChipCheckArray[nBoxIndex, nChipIndex] = checkBoxItem;

                    columnIndex++;
                }
                rowIndex++;
            }
        }

调用:

复制代码
/// <summary>
        /// 晶圆盒
        /// </summary>
        public WaferAutoForm()
        {
            InitializeComponent();

            initBoxUI();

            SetUIUserName("OP");
        }
相关推荐
3Q工具箱 - BraggTroy27 分钟前
Python + PyInstaller 实战:从零打造 10 个 Windows 桌面小工具(附全部踩坑记录与核心代码)
开发语言·windows·python
linnux领域30 分钟前
eNSP 交换机与电脑不在一个网段?用一台 Windows 双网卡做路由,把实验环境彻底打通
windows·华为·电脑·ensp·静态路由·网络实验·ensp模拟器
Quor1 小时前
Zorv AI GenUI 技术架构深度解析:从双面设计到安全边界
人工智能·ui·架构
挂科边缘1 小时前
Android Studio 保姆级安装教程,Windows 电脑上安装 Android Studio
android·windows·android studio
淡海水1 小时前
10-05-高级-模式匹配-CSharp如何改变与数据结构的交互方式
数据结构·算法·c#·模式匹配
TechExplorer3652 小时前
Win11 必要禁用的服务以释放进程内存
windows
XiaoZhenHua982 小时前
C# WinForms + 西门子S7 + SQLite + EPPlus生产数据采集系统架构设计
系统架构·sqlite·c#
江湖人称菠萝包2 小时前
【Windows】《深入浅出Windows API程序设计:核心编程篇》笔记-Chapter5-剪贴板
windows·笔记
Lost of 程序猿3 小时前
船岸数据同步链路实战:SendFlag、单调版本号与断网三天后的续传
后端·c#·asp.net
小此方4 小时前
告别云服务器连接困扰——Windows下利用VirtualBox安装配置Ubuntu虚拟机详细教程
服务器·windows·ubuntu