欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

代码如下:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace KK.ButtonLable
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            Add(new ButtonLable(), this.panel1, "");
            Add(new ButtonLable(), this.panel1, "");
            Add(new ButtonLable(), this.panel1, "");
            Add(new ButtonLable(), this.panel1, "");
            Add(new ButtonLable(), this.panel1, "");
        }

        /// <summary>
        /// 间隔
        /// </summary>
        private int UcMargin = 1;
        //private void Add(ButtonLable item, DICT_QUEUECODE queue, Panel panel, int colCount, string type)
        private void Add(ButtonLable item, Panel panel, string type)
        {
            //int index = queue.TIMEPART.IndexOf('~');
            //int num = queue.TIMEPART.Length - index - 1;
            //string beginTime = queue.TIMEPART.Substring(0, index);
            //string endTime = queue.TIMEPART.Substring(index + 1, num);
            if (panel.Controls.Count == 0)
                item.Location = new Point(UcMargin, UcMargin);
            else
            {
                int y = panel.Controls[0].Location.Y + item.Height * panel.Controls.Count + UcMargin;
                int x = panel.Controls[0].Location.X;
                item.Location = new Point(x, y);
            }

            //item.UCValue = queue.CODEVALUE.ToString() + "\n" + beginTime + "\n" + endTime;
            //item.DisplayValue = queue.CODEVALUE;
            //item.UcName = "btn" + type + queue.CODEVALUE;
            //item.Name = "btn" + type + queue.CODEVALUE;
            item.UcBtnValue = "aaa";
            item.UcLableValue = "bbb";
            item.SetBtn_OnClick(btnClick);

            panel.Controls.Add(item);
        }

        public void btnClick(object sender, EventArgs e) 
        {
            MessageBox.Show("Test");
        }
    }
}
 

运行效果如下:

posted on 2020-09-03 13:59  sunwugang  阅读(1132)  评论(0编辑  收藏  举报