Why in the world would the following simple code fail? This code always fills the path with the gradient from left to right, no matter which value of LinearGradientMode I use. graphPath is a GraphicPath object created elsewhere (basically a rounded rectangle):
Dim gradBrush as New LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical)
graphics.FillPath(gradBrush, graphPath)
UPDATE
To everyone's wonder, even this fails (draws horizontally). Simply create a new VB.NET WinForms project and paste the following code in Form1's Paint event:
Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim gradBrush As New LinearGradientBrush(Me.ClientRectangle, Color.Red, Color.White, LinearGradientMode.BackwardDiagonal)
e.Graphics.FillRectangle(gradBrush, Me.ClientRectangle)
End Sub
So I don't think this has anything to do with the path construction.
NOTE
I'll be glad if someone could just confirm this issue happens on their machines too, so that we know it is something with GDI+ and not my code. Just for reference, I have tried it on a WinXP VM and Win7 machine (32-bit, Aero mode) with .NET Fx 4.0 Client Profile and Full version.
FINALLY
First of all, thanks to all the great folks who helped me discover it. The problem was that I was editing someone else's code who had created an enum named exactly LinearGradientMode (to support the None option that he needed for his purpose). Now when he sent the object of this enum to LinearGradientBrush's constructor, C# compiler would think that the closest matching overload was the one that take "angle" parameter (this is my theory), and would convert the value of my gradient mode to equivalent int (0, 1, 2, 3 and 4 are the values) and call that constructor, resulting in a (nearly) horizontal gradient in each case.
Thanks again to everyone who participated.