Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
i include the following code in my application but again the flickering is happening.
 this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                    this.SetStyle(ControlStyles.DoubleBuffer |
               ControlStyles.OptimizedDoubleBuffer |
               ControlStyles.UserPaint |
               ControlStyles.AllPaintingInWmPaint, true);
                    this.UpdateStyles();
this code included inside
public Form1()
{}
Why this thing is happening..?
My application contains 1 form with 25 panels for different uses. when i select drop-down list items using keyboards down arrow,the form is flickering. first i couldn't realize that that thing is flickering. now i realize that is flickering and did something to remove flickering. but that's not working.
Posted 9-Oct-12 1:06am
Comments
sujeet101 at 9-Oct-12 8:09am
   
are you using any thread or any infinite loop for doing some task ??
ManjIndian at 9-Oct-12 9:15am
   
no.
Kschuler at 9-Oct-12 12:03pm
   
Why so many panels? Are they all being used at once? Are some of them hidden?
Sergey Alexandrovich Kryukov at 9-Oct-12 15:03pm
   
Those panels or some other controls may need optimized double buffering, not the form.
--SA
Sergey Alexandrovich Kryukov at 9-Oct-12 15:02pm
   
Not enough information. In most cases, you only need ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint. Also, this could be irrelevant to flicker it it is cased by some other controls. For those controls, you would also need the optimized double buffering. You can try to simplify application down to some very short code sample, or until flickering goes, and find out what causes it. After all, if you come to this point, you could post this sample using "Improve question".
--SA
ManjIndian at 10-Oct-12 0:42am
   
only 0ne is showing at once..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Stackover flow experts help me to solve this issue... Thanks to Stack overflow....
Yet another solution:
 
//TODO: Don't forget to include using System.Runtime.InteropServices.
internal static class NativeWinAPI
{
    internal static readonly int GWL_EXSTYLE = -20;
    internal static readonly int WS_EX_COMPOSITED = 0x02000000;
 
    [DllImport("user32")]
    internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
 
    [DllImport("user32")]
    internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}
And your form constructor should look as follows:
public MyForm()
{
    InitializeComponent();
 
    int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
    style |= NativeWinAPI.WS_EX_COMPOSITED;
    NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
}
In the code above, you might change this.Handle to something like MyFlickeringPanel.Handle
 
You can read a bit more about it here: Extended Window Styles and here: CreateWindowEx.
 
With WS_EX_COMPOSITED set, all descendants of a window get bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker.
 
share|edit

answered 23 mins ago
Nikolay Khil
864
  Permalink  
v2
Comments
ManjIndian at 10-Oct-12 7:05am
   
What you are edited?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Stackover flow experts help me to solve this issue... Thanks to Stack overflow....
Yet another solution:

//TODO: Don't forget to include using System.Runtime.InteropServices.
Collapse | Copy Code
 
internal static class NativeWinAPI
{
internal static readonly int GWL_EXSTYLE = -20;
internal static readonly int WS_EX_COMPOSITED = 0x02000000;

[DllImport("user32")]
internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32")]
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
}
 
And your form constructor should look as follows:
Collapse | Copy Code
 
public MyForm()
{
InitializeComponent();

int style = NativeWinAPI.GetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE);
style |= NativeWinAPI.WS_EX_COMPOSITED;
NativeWinAPI.SetWindowLong(this.Handle, NativeWinAPI.GWL_EXSTYLE, style);
}
 
In the code above, you might change this.Handle to something like MyFlickeringPanel.Handle

You can read a bit more about it here: Extended Window Styles and here: CreateWindowEx.

With WS_EX_COMPOSITED set, all descendants of a window get bottom-to-top painting order using double-buffering. Bottom-to-top painting order allows a descendent window to have translucency (alpha) and transparency (color-key) effects, but only if the descendent window also has the WS_EX_TRANSPARENT bit set. Double-buffering allows the window and its descendents to be painted without flicker.

share|edit
 
answered 23 mins ago
Nikolay Khil
864
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100