winform动态生成新窗体并添加控件执行命令

时间:2021-08-04 17:43:39

主要代码

 Form nf = new Form();
            int _w = 400;
            int _h = 400;
            nf.Width = _w;
            nf.Height = _h;
            //添加textbox
            TextBox tb = new TextBox();
            tb.Name = "txt";
            tb.Multiline = true;
            tb.Top = 0;
            tb.Left = 0;
            tb.Width = _w;
            tb.Height = _h;
            tb.Text = "哈哈哈哈哈哈";
            nf.Controls.Add(tb); 
            nf.Show();
            for (int i = 0; i < 200; i++)
            {
                tb.AppendText(i+"哈哈 \r\n");
            }

使用环境:

winform程序等待数据加载过程,显示loading图片等等

winform程序执行批量插入,如示例一样,实时显示情况