c# winform动态生成窗体及控件,并使用控件事件

winform动态生成窗体及控件,并使用控件事件

       private void 提交ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            shipei();
        }
        private void shipei()
        {
            win_shipei = new Form();
            GroupBox1 = new GroupBox();

            win_shipei.Name = "winsp";
            win_shipei.Size = new Size(884, 647);
            win_shipei.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

            GroupBox1.Text = "注册";
            GroupBox1.Size = new Size(819, 331);
            GroupBox1.Location = new Point(28, 12);

            win_shipei.Show();
            win_shipei.Controls.Add(GroupBox1);
            ArrayList aList = new ArrayList();
            aList.Add("a");
            aList.Add("b");
            aList.Add("c");
            aList.Add("d");
            aList.Add("e");
            aList.Add("f");
            aList.Add("g");
            aList.Add("h");
            for (int i = 1; i < 9; i++)
            {
                Label lb = new Label();
                lb.Name = "Label" + i.ToString();
                lb.Text = (string)aList[i - 1];
                lb.Location = new Point(35, 37 * i);
                lb.Size = new Size(150, 12);
                GroupBox1.Controls.Add(lb);
            }
            for (int i = 1; i < 9; i++)
            {
                tb = new TextBox();
                tb.Name = "textBox" + i.ToString();
                tb.Text = "";
                tb.Location = new Point(200, 37 * i);
                tb.Size = new Size(121, 21);
                GroupBox1.Controls.Add(tb);
            }            
            Button button = new Button();
            button.Name = "button";
            button.Text = "提交";
            button.Location = new Point(723, 349);
            button.Size = new Size(115, 23);
            button.Click += new EventHandler(shipei_Click);
            win_shipei.Controls.Add(button);

            tb = new TextBox();
            tb.Name = "log";
            tb.Location = new Point(28, 378);
            tb.Size = new Size(819, 204);
            tb.Multiline = true;
            tb.BorderStyle = BorderStyle.FixedSingle;
            win_shipei.Controls.Add(tb);
        }
        void shipei_Click(object sender, EventArgs e)
        {
              string textlog = "";
            for (int i = 1; i < 9;i++ )
            {
                TextBox text=win_shipei.Controls.Find("textBox"+i.ToString(), true)[0] as TextBox;
                par.Add (text.Text);
                textlog += text.Text;
            }
            TextBox tblog = win_shipei.Controls.Find("log", true)[0] as TextBox;
            tblog.AppendText(textlog);
        } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值