WinForms and C#, remove flickering from your Form.

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);


Leave a Reply