TableLayoutPanel使用

本文介绍了一个使用C#创建包含老人基本信息和服务详情的表格的方法。表格包括老人姓名、年龄、性别等基本信息,以及家庭住址、服务项目和服务金额等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

        /// <summary>
        /// 创建表格
        /// </summary>
        private void CreateTable()
        {
            int RowCount = 0;
            // 创建表格
            TableLayoutPanel table = new TableLayoutPanel();
            table.Dock = DockStyle.Fill;
            // 表格显示线条
            table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
            // 创建表格为8列
            table.ColumnCount = 8;
            #region 创建第一行显示内容内容
            Label labName = new Label()
            {
                Text = "老人姓名",
                Width = 80,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            // 第一行第一列值
            table.Controls.Add(labName, 0, RowCount);
            Label labNames = new Label()
            {
                Text = "张天",
                Width = 160,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            };
            table.Controls.Add(labNames, 1, RowCount);
            Label labAge = new Label()
            {
                Text = "年龄",
                Width = 80,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labAge, 2, RowCount);
            Label labAges = new Label()
            {
                Text = "88",
                Width = 80,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labAges, 3, RowCount);
            Label labSex = new Label()
            {
                Text = "性别",
                Width = 80,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labSex, 4, RowCount);
            Label labSexs = new Label()
            {
                Text = "男",
                Width = 80,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labSexs, 5, RowCount);
            Label labTypeName = new Label()
            {
                Text = "享受补助类别",
                Width = 160,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labTypeName, 6, RowCount);
            Label labTypeNames = new Label()
            {
                Text = "A类",
                Width = 160,
                Height = 30,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labTypeNames, 7, RowCount);
            #endregion
            #region 创建第二行
            RowCount++;
            Label labAddr = new Label()
            {
                Text = "家庭地址",
                Width = 80,
                Height = 30,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labAddr, 0, RowCount);
            Label labAddress = new Label()
            {
                Text = "湖南长沙芙蓉区",
                Height = 30,
                TextAlign = ContentAlignment.MiddleLeft,
                Dock = DockStyle.Fill
            };
            table.Controls.Add(labAddress, 1, RowCount);
            table.SetColumnSpan(labAddress, 7);
            #endregion
            #region 创建第三行
            RowCount++;
            Label labItemName = new Label()
            {
                Text = "服务项目",
                Height = 30,
                Width = 80,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labItemName, 0, RowCount);
            Label labServiceDetail = new Label()
            {
                Text = "服务明细",
                Height = 30,
                Width = 160,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labServiceDetail, 1, RowCount);
            Label labServiceDate = new Label()
            {
                Text = "服务时间",
                Height = 30,
                Width = 160,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labServiceDate, 2, RowCount);
            table.SetColumnSpan(labServiceDate, 2);
            Label labServeMoney = new Label()
            {
                Text = "服务金额",
                Height = 30,
                Width = 160,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labServeMoney, 3, RowCount);
            table.SetColumnSpan(labServeMoney, 2);
            Label labEmpName = new Label()
            {
                Text = "服务员工",
                Width = 160,
                Height = 30,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labEmpName, 4, RowCount);
            Label labDetail = new Label()
            {
                Text = "备注",
                Width = 160,
                Height = 30,
                TextAlign = ContentAlignment.MiddleCenter
            };
            table.Controls.Add(labDetail, 5, RowCount);
            #endregion
            RowCount += 2;
            table.RowCount = RowCount;
            this.tableLayoutPanel1.Controls.Add(table, 0, 2);
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值