避免在WindowsForms中闪烁 [英] Avoid flicker in WindowsForms

查看:69
本文介绍了避免在WindowsForms中闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的usecontrol类似于TabControl。我在usercontrol的每个TabPages中添加了许多子控件。在更改选定的选项卡时,TabControl闪烁。我也在标准TabControl中看到了相同的行为。


最初我试图避免使用Doublebuffered闪烁。这似乎没有解决问题。我们还使用了下面的代码示例。


代码示例[C#]:

 < code style ="margin:0px; padding:0px; border:0px; font-size:13px; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,sans-serif; white-space:inherit">  SetStyle    ControlStyles    UserPaint     |   
ControlStyles AllPaintingInWmPaint |
ControlStyles DoubleBuffer true

但是这个案例没有解决闪烁的问题。最后我们尝试了CreateParams as如下所示。

  

受保护的覆盖CreateParams CreateParams 
{
get
{
CreateParams cp = base.CreateParams; cp.ExStyle | = 0x02000000;
return cp;
}
}



这解决了闪烁问题,但导致绘画问题与一些子控件。任何人都可以指导我如何解决没有使用CreateParams的闪烁问题?因为这个CreateParams在应用程序中引起许多副作用。

解决方案


尝试使用 BeginUpdate(),EndUpdate()为UserControl优化代码  when&n bsp;你的UserControl 做大量的绘图(比如列表框添加项目)。


在表单上创建大量控件时,尝试使用SuspendLayout(),ResumeLayout减少表单布局逻辑的次数()通过编程。 


尝试覆盖  WndProc方法禁止删除背景信息。

 protected override void WndProc(ref message m)
{
if(m.Msg == 0x0014)
return;
base.WndProc(ref m);
}

希望这对您有所帮助。


最好的问候,


鲍勃


Hi All,

I have usecontrol similar to TabControl. I have added many child controls in each TabPages of the usercontrol. On changing the selected Tab, the TabControl flickers. I have also see this same behavior in Standard TabControl.

Initially I have tried to avoid the flickering using Doublebuffered. This doesn't seems to resolve the issue. We have also used tried below code example.

Code Example[C#]:

SetStyle(ControlStyles.UserPaint |
         ControlStyles.AllPaintingInWmPaint |
         ControlStyles.DoubleBuffer, true)

But this cases didn't resolved the flickering issue. Finally we have tried the CreateParams as shown below.

  

      protected override CreateParams CreateParams   
      { 
        get
          {      
          CreateParams cp = base.CreateParams;                                           cp.ExStyle |= 0x02000000; 
               return cp;        
           }
       }


This resolved the flickering issue, but cause the painting issues with some child controls. Could anyone guide me how to resolve the flickering issue without using CreateParams? Because this CreateParams cause many side effects in the application.

解决方案

Hi,

Try to optimize your code by using BeginUpdate(),EndUpdate() for a UserControl when your UserControl  do lots of drawing(like listbox add items).

Try to decrease times of layout logic for the form by using SuspendLayout(), ResumeLayout when you create lots of controls on the form() by programing. 

Try to override WndProc method to ban to remove background information.

   protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0014) 
                return;
            base.WndProc(ref m);
        }

Hope this can be helpful to you.

Best Regards,

Bob


这篇关于避免在WindowsForms中闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆