zoukankan      html  css  js  c++  java
  • Winform 自定义控件 添加至panel 处理自定义控件事件

    代码如下:

    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() + "
    " + beginTime + "
    " + 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");
            }
        }
    }
     

    运行效果如下:

  • 相关阅读:
    hdu 3715(二分+2-sat)
    hdu 3622(二分+2-sat判断可行性)
    hdu 3062+1824(2-sat入门)
    【转载】lucene中Field.Index,Field.Store详解
    【转载】那些年我们一起清除过的浮动demo
    【转载】那些年我们一起清除过的浮动
    【转载】Visaul Studio 常用快捷键的动画演示
    【转载】各浏览器CSS兼容问题
    【转载】HTTP 错误 500.19
    【转载】Memcached在.Net中的基本操作
  • 原文地址:https://www.cnblogs.com/YYkun/p/13607183.html
Copyright © 2011-2022 走看看