Monday, May 30, 2011

Flicker free controls: SplitContainer

.Net Flicker Fee Controls 


Here are the steps to use this control:
1. Add new class "NonFlickerSplitContainer" to your C# application.
2. Replace auto generated class code with C# code shown below.
3. Use NonFlickerSplitContainer object instead of SplitContainer object in your application.

    public partial class NonFlickerSplitContainer : SplitContainer
    {
        public NonFlickerSplitContainer()
        {
            this.SetStyle(ControlStyles.AllPaintingInWmPaint |
                               ControlStyles.UserPaint |
                               ControlStyles.OptimizedDoubleBuffer, true);

            MethodInfo objMethodInfo = typeof(Control).GetMethod(             "SetStyle",BindingFlags.NonPublic|BindingFlags.Instance);

            object[] objArgs = new object[] { ControlStyles.AllPaintingInWmPaint |
                                                                ControlStyles.UserPaint |
                                                               ControlStyles.OptimizedDoubleBuffer, true };

            objMethodInfo.Invoke(this.Panel1, objArgs);
            objMethodInfo.Invoke(this.Panel2, objArgs);
        }
    }

Flicker free controls: ListView

.Net Flicker Fee Controls 


Here are the steps to use this control:
1. Add new class "NonFlickerListView" to your C# application.
2. Replace auto generated class code with C# code shown below.
3. Use NonFlickerListView object instead of ListView object in your application.
   
public partial class NonFlickerListView : ListView
    {
        public NonFlickerListView()
        {
            this.GetType().GetProperty("DoubleBuffered",
System.Reflection.BindingFlags.NonPublic |                                                      System.Reflection.BindingFlags.Instance
).SetValue(this, true, null);
        }

            protected override void WndProc(ref Message messg)
        {
            if ((int)0x0014 == messg.Msg) // if message is is erase background
            {
                messg.Msg = (int)0x0000; // reset message to null
                return;
            }
            base.WndProc(ref messg);

        }
    }

Friday, May 27, 2011

Flicker free controls: GroupBox

.Net Flicker Fee Controls

Here are the steps to use this control:
1. Add new class "NonFlickerGroupBox" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerGroupBox object instead of GroupBox object in your application.

public partial class NonFlickerGroupBox : GroupBox
{
        public NonFlickerGroupBox() : base()
       {
                   this.SetStyle(ControlStyles.AllPaintingInWmPaint,
                                       ControlStyles.UserPaint
                                       ControlStyles.OptimizedDoubleBuffer,
                                       true);
       }
}

Fell free to post any query.

Flicker free controls: Panel

.Net Flicker Fee Controls
In first post Iam gonna post code of Filcker free Panel control. You can use this control in your application.

Here are the steps to use this control:
1. Add new class "NonFlickerPanel" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerPanel object instead of Panel object in your application.

public partial class NonFlickerPanel : Panel
{
       public NonFlickerPanel() : base()
       {
              this.SetStyle(ControlStyles.AllPaintingInWmPaint,
                                  ControlStyles.UserPaint
                                  ControlStyles.OptimizedDoubleBuffer,
                                  true);
       }
}
 
Fell free to post any query.