none
请教关于winform设计UI闪屏的问题 RRS feed

  • 问题

  • public partial class Form1 : Form
        {
            UserControl uc1 = new UserControl1();
            UserControl uc2 = new UserControl2();
            public Form1()
            {
                InitializeComponent();
                this.DoubleBuffered = true;
                this.BackgroundImage = Image.FromFile("a1.jpg");
                uc1.BackColor = Color.Red;
                uc1.Dock = DockStyle.Fill;
                uc2.BackColor = Color.Blue;
                uc2.Dock = DockStyle.Fill;
                uc2.Visible = false;
                Button btn = new Button();
                btn.Text = "切换";
                btn.Click += new EventHandler(btn_Click);
                Panel p = new Panel();
                p.Dock = DockStyle.Fill;
                p.Controls.Add(uc1);
                p.Controls.Add(uc2);
                TableLayoutPanel tlp = new TableLayoutPanel();
                tlp.ColumnCount = 1;
                tlp.RowCount = 2;
                tlp.BackColor = Color.Transparent;
                tlp.Dock = DockStyle.Fill;
                tlp.Controls.Add(btn, 0, 0);
                tlp.Controls.Add(p, 0, 1);
                this.Controls.Add(tlp);
            }
            void btn_Click(object sender, EventArgs e)
            {
                uc1.Visible = !uc1.Visible;
                uc2.Visible = !uc2.Visible;
            }
        }
        public partial class UserControl1 : UserControl
        {
        }
        public partial class UserControl2 : UserControl
        {
        }

    单击切换按钮,会切换两个UserControl,在切换的过程中会出现背景闪烁的问题。

    这个问题困扰我好久了,求高手解答。谢谢

    2012年7月4日 1:15

答案

全部回复