积极答复者
请教关于winform设计UI闪屏的问题

问题
-
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,在切换的过程中会出现背景闪烁的问题。
这个问题困扰我好久了,求高手解答。谢谢
答案
-
使用如下方法试试
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
也可以参照下这个帖子:
http://blog.csdn.net/zx13525079024
- 已建议为答案 Jason Dot WangModerator 2012年7月5日 7:45
- 已标记为答案 Jason Dot WangModerator 2012年7月11日 7:37
-
使用如下方法试试
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
也可以参照下这个帖子:
http://blog.csdn.net/zx13525079024
先谢谢 开心
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
代码加上后问题依旧。
下面那个例子我也看了,设置了TableLayoutPanel的双缓冲后还是闪烁。
我的闪烁是显示UserControl之前会先闪一下背景图片,然后才显示UserControl的颜色。我觉得问题应该是出在TableLayoutPanel的 BackColor = Color.Transparent;
我吧背景改为默认色就不会闪烁背景。
- 已标记为答案 Jason Dot WangModerator 2012年7月11日 7:37
全部回复
-
使用如下方法试试
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
也可以参照下这个帖子:
http://blog.csdn.net/zx13525079024
- 已建议为答案 Jason Dot WangModerator 2012年7月5日 7:45
- 已标记为答案 Jason Dot WangModerator 2012年7月11日 7:37
-
使用如下方法试试
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
也可以参照下这个帖子:
http://blog.csdn.net/zx13525079024
先谢谢 开心
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.UpdateStyles();
代码加上后问题依旧。
下面那个例子我也看了,设置了TableLayoutPanel的双缓冲后还是闪烁。
我的闪烁是显示UserControl之前会先闪一下背景图片,然后才显示UserControl的颜色。我觉得问题应该是出在TableLayoutPanel的 BackColor = Color.Transparent;
我吧背景改为默认色就不会闪烁背景。
- 已标记为答案 Jason Dot WangModerator 2012年7月11日 7:37