LinearGradientBrush problems filling a polygon

C

C

I haven't understood what the first rectangle parameter in the brush
Dim is. I have done the following and it produces nonsense.

Dim frmImage As Bitmap = New Bitmap(1000, 800)

Sub drawArrow(ByVal g As Graphics, ByVal hv As Short, ByVal arrowL
As Short, ByVal arrowThick As Short, ByVal arrowW As Short)

Dim arrowPoints(7) As Point
Dim rect As Rectangle = New Rectangle(60, 10, 90, 40)
Dim arrowBrush As System.Drawing.Drawing2D.LinearGradientBrush
= New System.Drawing.Drawing2D.LinearGradientBrush(rect,
Color.GreenYellow, Color.Red,
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)

arrowPoints(1) = New Point(60, 20)
arrowPoints(2) = New Point(120, 20)
arrowPoints(3) = New Point(120, 10)
arrowPoints(4) = New Point(150, 30)
arrowPoints(5) = New Point(120, 50)
arrowPoints(6) = New Point(120, 40)
arrowPoints(7) = New Point(60, 40)

g.FillPolygon(arrowBrush, arrowPoints)

' Will use hv, arrowL, etc. later on. First I should get it to show an
arrow with a proper gradient.

Me.Invalidate()

End Sub

Private Sub Label3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Label3.Click
Dim g As Graphics = Graphics.FromImage(frmImage)
Call drawArrow(g, 1, 100, 12, 24)
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(frmImage, 0, 0)
End Sub

What am I doing wrong?
Thanks.
 
A

Armin Zingler

Am 17.08.2010 19:47, schrieb C:
Dim arrowPoints(7) As Point

Dim arrowPoints(6) As Point
arrowPoints(1) = New Point(60, 20)
arrowPoints(2) = New Point(120, 20)
arrowPoints(3) = New Point(120, 10)
arrowPoints(4) = New Point(150, 30)
arrowPoints(5) = New Point(120, 50)
arrowPoints(6) = New Point(120, 40)
arrowPoints(7) = New Point(60, 40)


arrowPoints(0) = New Point(60, 20)
arrowPoints(1) = New Point(120, 20)
arrowPoints(2) = New Point(120, 10)
arrowPoints(3) = New Point(150, 30)
arrowPoints(4) = New Point(120, 50)
arrowPoints(5) = New Point(120, 40)
arrowPoints(6) = New Point(60, 40)


:)
 
C

CSquared

Armin said:
Am 17.08.2010 19:47, schrieb C:

Dim arrowPoints(6) As Point



arrowPoints(0) = New Point(60, 20)
arrowPoints(1) = New Point(120, 20)
arrowPoints(2) = New Point(120, 10)
arrowPoints(3) = New Point(150, 30)
arrowPoints(4) = New Point(120, 50)
arrowPoints(5) = New Point(120, 40)
arrowPoints(6) = New Point(60, 40)


:)
Errrrmmm, If you have seven sets of values, aren't you going to need
that to still be arrowPoints[7]? :)
Later,
Charlie C.
 
A

Andrew Morton

CSquared said:
Errrrmmm, If you have seven sets of values, aren't you going to need
that to still be arrowPoints[7]? :)

No, because the index goes 0,1,2,3,4,5,6 for seven values.

And when you declare an array in VB.NET, you tell it the last index, not the
number of elements in the array.
 
A

Armin Zingler

Am 19.08.2010 10:07, schrieb Andrew Morton:
CSquared said:
Errrrmmm, If you have seven sets of values, aren't you going to need
that to still be arrowPoints[7]? :)

No, because the index goes 0,1,2,3,4,5,6 for seven values.

I think the square brackets should say that it he knows it
as the [count] from "somewhere else".
And when you declare an array in VB.NET, you tell it the last index, not the
number of elements in the array.

....because, in previous VB versions, we were able to specify the upper
and the lower bounds: "Dim range(-42 To 17) as long", so we could access
range(-42)....range(17). As the lower bounds were optional, we could
also write "Dim range(5) as long", but it's still the upper bounds.
Otherwise the meaning of the value would have changed from
bound to count, which would've been confusing. As this behavior
is "built into" every VB programmer, it wasn't changed in VB.Net.
Would have caused even more trouble.
 
C

CSquared

Armin said:
Am 19.08.2010 10:07, schrieb Andrew Morton:
CSquared said:
Errrrmmm, If you have seven sets of values, aren't you going to need
that to still be arrowPoints[7]? :)
No, because the index goes 0,1,2,3,4,5,6 for seven values.

I think the square brackets should say that it he knows it
as the [count] from "somewhere else".
And when you declare an array in VB.NET, you tell it the last index, not the
number of elements in the array.

...because, in previous VB versions, we were able to specify the upper
and the lower bounds: "Dim range(-42 To 17) as long", so we could access
range(-42)....range(17). As the lower bounds were optional, we could
also write "Dim range(5) as long", but it's still the upper bounds.
Otherwise the meaning of the value would have changed from
bound to count, which would've been confusing. As this behavior
is "built into" every VB programmer, it wasn't changed in VB.Net.
Would have caused even more trouble.
Wow, thanks, I did not know that. As you can guess, I'm really new at
this VB stuff - any flavor. I just sort of assumed (wrongly) that if
the first member of an array in .net is now at index 0 (rather C-like)
then the array dimensions would also be C-like. Nice to know I was
wrong. Of course y'all are quite correct about the "somewhere else"
part too. :)
Thanks,
Charlie C.
 

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

Top