Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i include the following code in my application but again the flickering is happening.
C#
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                   this.SetStyle(ControlStyles.DoubleBuffer |
              ControlStyles.OptimizedDoubleBuffer |
              ControlStyles.UserPaint |
              ControlStyles.AllPaintingInWmPaint, true);
                   this.UpdateStyles();

this code included inside
C#
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
Comments
sujeet101 9-Oct-12 8:09am    
are you using any thread or any infinite loop for doing some task ??
ManjIndian 9-Oct-12 9:15am    
no.
Kschuler 9-Oct-12 12:03pm    
Why so many panels? Are they all being used at once? Are some of them hidden?
Sergey Alexandrovich Kryukov 9-Oct-12 15:03pm    
Those panels or some other controls may need optimized double buffering, not the form.
--SA
Sergey Alexandrovich Kryukov 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

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.
C#
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:
C#
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
 
Share this answer
 
v2
Comments
ManjIndian 10-Oct-12 7:05am    
What you are edited?
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900