C#解决窗体不闪烁

来源:互联网 发布:淘宝日本男装品牌 编辑:程序博客网 时间:2024/05/17 06:56

  private void Form1_Load(object sender, EventArgs e)
        {
            this.DoubleBuffered = true;
            Button[] btn = new Button[30];
            int iIndex = 0, iWidth = 0, iHeigth = 0;

            iWidth = this.Width / 5;
            iHeigth = this.Height / 6;

            this.SuspendLayout();
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    btn[iIndex] = new Button();
                    btn[iIndex].Text = "btn" + iIndex.ToString();
                    btn[iIndex].Left = btn[0].Width * j;
                    btn[iIndex].Top = btn[0].Height * i;
                    btn[iIndex].Width = iWidth;
                    btn[iIndex].Height = iHeigth;
                    iIndex++;
                }
            }

            this.Controls.AddRange(btn);

            this.ResumeLayout();
        }

原创粉丝点击