[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Filling a panel with a LinearGradientBrush brush

programmingscoobydoo

12/22/2004 9:47:00 AM

Hi,
I'm not doing this for any particular reason, but was just playing
with specialising windows controls. It's driven me mad...

I wanted to create a control, derived from System.Windows.Forms.Panel
(though, i started with System.Windows.Forms.UserControl) that fills
itself with a gradient.

I made it rotate in response to a timer etc. - The drawing code is in
the onPaint override.

I seemed to work ok, until the angle is 180degrees. In stead of being
a smooth white to black transition, it starts with a 1 pixel wide,
black, vertical column of pixels.


///this recreates the problem:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint (e);

Rectangle r = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
ClientRectangle.Width, ClientRectangle.Height);

LinearGradientBrush b = new LinearGradientBrush(r,Color.Black,
Color.White, 180, false);

e.Graphics.FillRectangle(b,r);
}



If I replace the brush declaration - (swapping colours and setting
the angle to 0) - no such line appears. Everything looks well:

LinearGradientBrush b = new LinearGradientBrush(r,Color.White,
Color.Black, 0, false);

The Size of the panel is 100,100.

What have I missed? Why do I get the line?

Dave.
3 Answers

Bob Powell

12/22/2004 11:38:00 AM

0

I have seen this before on several occasions and I think it's due to a bug
in the gradient calculation.

I usually cure the problem by making the gradient rectangle a wee bit bigger
than the destination rectangle. A pixel either way, width and height,
usually does it.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"scoobydoo" <programmingscoobydoo@hotmail.com> wrote in message
news:4e04147b.0412220146.7ec638eb@posting.google.com...
> Hi,
> I'm not doing this for any particular reason, but was just playing
> with specialising windows controls. It's driven me mad...
>
> I wanted to create a control, derived from System.Windows.Forms.Panel
> (though, i started with System.Windows.Forms.UserControl) that fills
> itself with a gradient.
>
> I made it rotate in response to a timer etc. - The drawing code is in
> the onPaint override.
>
> I seemed to work ok, until the angle is 180degrees. In stead of being
> a smooth white to black transition, it starts with a 1 pixel wide,
> black, vertical column of pixels.
>
>
> ///this recreates the problem:
> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
> {
> base.OnPaint (e);
>
> Rectangle r = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
> ClientRectangle.Width, ClientRectangle.Height);
>
> LinearGradientBrush b = new LinearGradientBrush(r,Color.Black,
> Color.White, 180, false);
>
> e.Graphics.FillRectangle(b,r);
> }
>
>
>
> If I replace the brush declaration - (swapping colours and setting
> the angle to 0) - no such line appears. Everything looks well:
>
> LinearGradientBrush b = new LinearGradientBrush(r,Color.White,
> Color.Black, 0, false);
>
> The Size of the panel is 100,100.
>
> What have I missed? Why do I get the line?
>
> Dave.


scoobydoo

12/22/2004 1:09:00 PM

0

Bob,
Thanks for your reply...
A potential bug huh? Well, at least I'm not going too mad.

The only fix/hack I found (other than to do as you say, and paint over a
bigger area), is to set the brush's Wrap mode...

br.WrapMode = System.Drawing.Drawing2D.WrapMode.TileFlipX;

I'm don't think its an answer, but just a suggestion i found during a
search. not sure of its side-effects.

Oh, and great tutorials!

Dave.




"Bob Powell [MVP]" wrote:

>
> I usually cure the problem by making the gradient rectangle a wee bit bigger
> than the destination rectangle. A pixel either way, width and height,
> usually does it.
>

Aviroce

6/14/2013 3:08:00 AM

0

Let Israel do it by itself.


On Monday, June 10, 2013 10:48:31 PM UTC-7, CUNTICA wrote:
> '' Ireland and Sweden fearing for the safety of a UN peacekeeping mission in the region.'' Oh, there's big news...... These fucks are like the damn Dutch & Germans, just cowards hiding in their bunkers!