zoukankan      html  css  js  c++  java
  • 动态创建5个按钮

    新建HTML文档

    动态创建5个按钮

               for (int i = 0; i < 5; i++)
                {
                    Button button = new Button();
                    button.Location = new Point(button.Width *i, 10);
                    //button.Click += new EventHandler(ButtonClickOneEvent);
                    button.Tag = i;
                    Controls.Add(button);
                }

            private void button1_Click(object senderEventArgs e)
            {
                string s = textBox1.Text;
                string[] arr = s.Split(new string[] { "\",}, StringSplitOptions.None);
                string s1 = "";
                int distance = 10;
                Button[] btns = new Button[arr.Length];
                for (int i = 0; i < arr.Length;i++ )
                {
                    string name = string.Format("{0} "arr[i]);
                    s1 += name;
     
                    Button btn = new Button();
                    btn.Text = name;
                    btn.Tag = i;
     
                    Size size = TextRenderer.MeasureText(namebtn.Font);
                    btn.Width = size.Width+20;
     
                    btn.Location = new Point(distance, 10);
                    distance += size.Width + 20;
                    
     
                    Controls.Add(btn);
                }
                richTextBox1.Text = s1;

            }  

  • 相关阅读:
    git 入门操作
    ubuntu apc 安装
    vps mysql自动关闭
    xdebug安装
    C#获取IP和主机名
    C#在类中用调用Form的方法
    luogu3181 [HAOI2016]找相同字符
    luogu6139 【模板】广义后缀自动机(广义SAM)
    广义后缀自动机小结
    Codeforces Round #620 (Div. 2) 题解
  • 原文地址:https://www.cnblogs.com/xe2011/p/3859037.html
Copyright © 2011-2022 走看看