Article Cruise

Latest news, Technologies, TV series, Movies, Design and Fashion, DIY

WinForms and C#, remove flickering from your Form.

Posted on | October 10, 2014 | No Comments

To remove the flickering from your form, add the following line to your C# application, beware of compatibility issues with Windows XP (You might face some problems when loading images dynamically)

 



#region .. Double Buffered function ..
 public static void SetDoubleBuffered(System.Windows.Forms.Control c)
 {
      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);
 }

#endregion


 #region .. code for Flickering..
protected override CreateParams CreateParams
 {
     get{
         if (OS.IsWinVistaOrHigher()){
              CreateParams cp = base.CreateParams;
              cp.ExStyle |= 0x02000000;
              return cp;
        }else{
              return base.CreateParams;
        }
     }
 }

#endregion

#region WindowsVista and above check
 public static bool IsWinVistaOrHigher()
 {
     OperatingSystem OS = Environment.OSVersion;
     return (OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6);
 }
#endregion

SetDoubleBuffered(this.panel_mixing);


Comments

Search

Admin message

The articles posted in French are different than the ones in English!

Social

Archives

About

We post what we think, we post news, we post...

Subscribe to our feed

Admin