zoukankan      html  css  js  c++  java
  • (Winform)控件中添加GIF图片以及运用双缓冲使其不闪烁以及背景是gif时使控件(如panel)变透明

    Image img = Image.FromFile(@"C:UsersjoeymaryDesktop3.gif");
    pictureBox1.Image =img.Clone() as Image;
    //label1.Image = img.Clone() as Image;
    label1.Size = img.Size;
    img.Dispose();

    label跟pictureBox中均可使用。

    由于窗体重绘会导致控件闪烁

    方法一:

    /// <summary>
    /// 重写Form的CreateParams属性,对控件做二次缓冲(double buffer)
    /// </summary>
    protected override CreateParams CreateParams//牛逼啊!居然不闪了~~~
    {
    get
    {
    CreateParams cp = base.CreateParams;
    cp.ExStyle |= 0x02000000;
    return cp;
    }
    }

    第二个方法是设置控件的DoubleBuffered属性,需要注意这一属性是私有的,要设置此属性需要使用反射。

    这个方法没试过,毕竟看着晕

    public static void SetDoubleBuffered(System.Windows.Forms.Control c)
    {
       //请参考下面的博客
       //http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx
       if (System.Windows.Forms.SystemInformation.TerminalServerSession)
          return;
    
       System.Reflection.PropertyInfo aProp = 
             typeof(System.Windows.Forms.Control).GetProperty(
                   "DoubleBuffered", 
                   System.Reflection.BindingFlags.NonPublic | 
                   System.Reflection.BindingFlags.Instance);
    
       aProp.SetValue(c, true, null); 
    }

    //this.panel1.BackColor = Color.Transparent;//将Panel设为透明
    //this.panel1.Parent = this.pictureBox1;//将panel父控件设为背景图片控件
    //this.panel1.BringToFront();//将panel放在前面

  • 相关阅读:
    SSHkey的申请
    版本控制系统-集中式VS分布式(分享)
    01-OC中数组NSArray的遍历
    第4周小组作业:WordCount优化
    第2周作业1:开设博客
    第2周个人作业:WordCount
    测试课程总结2017
    优秀博客的评比结果及相关说明
    静态代码检查工具简介
    Selenium安装中的一些问题及解决办法-软硕1703班3组整理分享
  • 原文地址:https://www.cnblogs.com/joeymary/p/4596274.html
Copyright © 2011-2022 走看看