(Winform)コントロールにGIFピクチャを追加したり、ダブルバッファで点滅させないようにしたり、背景がgifの場合パネルなどを透明にしたりします

3675 ワード

Image img = Image.FromFile(@"C:\Users\joeymary\Desktop\3.gif"); pictureBox1.Image =img.Clone() as Image;//label1.Image = img.Clone() as Image;label1.Size = img.Size; img.Dispose();
LabelとpictureBoxでも使用できます.
フォームの再描画によりコントロールが点滅する
方法1:
///////FormのCreateParams属性を書き換え、コントロールに二次バッファを作ります//protected override CreateParams CreateParams//牛逼!フラッシュしないなんて~~~{get{CreateParams cp=base.CreateParams;cp.ExStyle|=0 x 02000;return cp;}
2つ目の方法は、コントロールの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;//パネルを透明にする/this.panel1.Parent = this.pictureBox1;//パネルの親コントロールを背景画像コントロール//thisに設定します.panel1.BringToFront();//パネルを前に置く