all groups > dotnet windows forms designtime > october 2005 >
You're in the

dotnet windows forms designtime

group:

Error on LinearGradientBrush


Re: Error on LinearGradientBrush Bob Powell [MVP]
10/2/2005 12:00:00 AM
dotnet windows forms designtime: This is a known error (at least known to me) with LinearGradientBrush. It
seems that the colour gradient is calculated slightly too short. The
work-around is to make the gradient 1 pixel larger than the destination
drawing rectangle.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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

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

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





[quoted text, click to view]

Re: Error on LinearGradientBrush Carlo, MCP
10/2/2005 12:00:00 AM
Hello Bob
I'm very glad to meet you on the ng. I recently used your page named "The ToolboxBitmap puzzle"!

Thank you for the suggestion. Applying your suggestion means that I'll get rectangles that overflows my needs by 1
pixel.
Unfortunately, this is unacceptable for my needs since I calculate rectangles sizes based on MeasureString for a very
accurate placement of text(s) and image(s) on the control.
Thank you for replying

Carlo



"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> ha scritto nel messaggio
news:%2322vS30xFHA.1284@tk2msftngp13.phx.gbl...
[quoted text, click to view]

Error on LinearGradientBrush Carlo
10/2/2005 2:00:02 AM
Hello

I found an abnormal behaviour on LinearGradientBrush (or FillRectangle).
This code

Public Class PanelPanel
Inherits System.Windows.Forms.Panel
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim rect As System.Drawing.Rectangle = New
System.Drawing.Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As System.Drawing.Drawing2D.LinearGradientBrush
gradientBrush = New System.Drawing.Drawing2D.LinearGradientBrush(rect, _
System.Drawing.Color.Gray, _

System.Drawing.Color.FloralWhite, _

System.Drawing.Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(gradientBrush, rect)
End Sub
End Class

generates a control with an rectangle drawn inside.
The problem is that an unusual line (colored Color.FloralWhite) appears on
the top edge of the rectangle. This line should not be there.
If LinearGradientMode id other than Vertical the problem persists, but it is
less visible (only a small colored pixel is visible).

Please note that the anomaly appears only with some rectangle sizes. Example:
if rect={X=10,Y=10,Width=304,Height=208} 'equivalent to a Me.Size=New
Size(324,228) - Anomaly visible
if rect={X=10,Y=10,Width=304,Height=216} 'Correct, anomaly not visible

Could someone PLEASE try to reproduce the problem (just copy code as is) and
confirm that is an error and then reason with me??

Thank you!.

Carlo

(MCP)

Re: Error on LinearGradientBrush Bob Powell [MVP]
10/3/2005 12:00:00 AM
A good alternative too...

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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

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

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





[quoted text, click to view]

Re: Error on LinearGradientBrush Frank Hileman
10/3/2005 8:22:10 AM
Change the WrapMode to TileFlipXY.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

[quoted text, click to view]

Re: Error on LinearGradientBrush Frank Hileman
10/4/2005 1:49:13 PM
WrapMode works both with LinearGradientBrush and PathGradientBrush. Just set
the WrapMode property on gradientBrush before you draw with it.

Here is the problem: internally GDI+ has a small rounding error when
computing the start and end coordinates of the gradient. This results in 1
pixel of the next gradient showing in your rectangle. Since the default
WrapMode is Tile, the next gradient will begin with a contrasting color, so
that 1 pixel line is obvious. If you change the wrap mode to flip the
gradient, the next gradient will begin with the same color which just ended,
and the error is no longer visible.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

[quoted text, click to view]

Re: Error on LinearGradientBrush Carlo, MCP
10/4/2005 7:46:19 PM
I never heard about WrapMode before. I've seen it is applicable only to
PathGradientBrush.
I've no ideas on how draw my gradient rectangles using PathGradientBrush
(and WrapMode).

Could you please be more precise or write a pair of rows as an example?

This is my original code:

Dim rect As Rectangle = New Rectangle(10, 10, Me.Width - 20, Me.Height - 20)
Dim gradientBrush As Drawing2D.LinearGradientBrush
gradientBrush = New Drawing2D.LinearGradientBrush(rect, Color.Gray,
Color.FloralWhite, Drawing2D.LinearGradientMode.Vertical)
e.Graphics.FillRectangle(gradientBrush, rect)


Thank you, and regards,

Carlo




[quoted text, click to view]

Re: Error on LinearGradientBrush Carlo, MCP
10/5/2005 8:38:46 AM
Thank you for the reply and for the suggestion. I'm very happy because it
works!

Best Regards,

Carlo



"Frank Hileman" <frankhil@no.spamming.prodigesoftware.com> ha scritto nel
messaggio news:O2EMVUSyFHA.916@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button