Flickering of gradient rectangle

L

LightWarrior

Hello,

I created an panel in my form. In the Paint event of this panel I
created a gradient rectangle...
Like you can see in this code:

Rectangle rect = new Rectangle(0, 0, this.panel1.Width,
this.panel1.Height);

LinearGradientBrush m_brush = new LinearGradientBrush(rect,
SystemColors.Highlight, SystemColors.GradientInactiveCaption,
LinearGradientMode.ForwardDiagonal);

e.Graphics.FillRectangle(m_brush, rect);

PointF left = new PointF(0, this.panel1.Height - 1);
PointF right = new PointF(this.panel1.Width, this.panel1.Height - 1);

e.Graphics.DrawLine(SystemPens.ControlLightLight, left, right);

In the form constructur I already set these styles:
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);
UpdateStyles();

The problem is that when I resize the window (in my test app the panel
is docked in the form) the gradient rectangle is flickering. What I
want is a rectangle that is resizing when I resize my form. But without
flickering...

Can somebody help me!?

Greetings!
LW
 
Ö

Özden Irmak

Hello,

Although you set the doublebuffer for your form, you didn't do for the panel
control...Simply derive a control from Panel setting those doublebuffer
flags and use this control to draw your gradient...

Hope it helps...

Özden
 
L

LightWarrior

Hallo Özden,

thanks for your suggestion, but it still doesn't help. I created a
panelEx which derives from panel. But is still flickers when I resize
the form.

Here you see the source:

public partial class PanelEx : Panel
{
public PanelEx()
{
InitializeComponent();

SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);

SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}

public PanelEx(IContainer container)
{
container.Add(this);

InitializeComponent();
}
}

Greetings,
LW

Özden Irmak (at) schreef:
 
Ö

Özden Irmak

Hello,

It is a fact that in WindowsForms, you cannot get %100 smooth drawing when
controls are resized but as you said it flickers, I assume you see somekind
of flash with your drawing and a gray backcolor right?

Also, if you don't mind, send that form so I can check whether what's wrong?

Özden

Hallo Özden,

thanks for your suggestion, but it still doesn't help. I created a
panelEx which derives from panel. But is still flickers when I resize
the form.

Here you see the source:

public partial class PanelEx : Panel
{
public PanelEx()
{
InitializeComponent();

SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);

SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}

public PanelEx(IContainer container)
{
container.Add(this);

InitializeComponent();
}
}

Greetings,
LW

Özden Irmak (at) schreef:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top