I have an array of TextureBrush() which I call upon to fill a rectangle. However, I am coming up against an error:
System.ArgumentNullException was unhandled
HResult=-2147467261
Message=Value cannot be null.
Parameter name: brush
ParamName=brush
Source=System.Drawing
StackTrace:
at System.Drawing.Graphics.FillRectangle(Brush brush, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.FillRectangle(Brush brush, Rectangle rect)
So my question: Is it not possible to fill a rectangle with a texture brush?
Code:
'Sub to load all the textures called in the onLoad event.
Private Sub loadTextures()
Dim Junk1 As Rectangle = New Rectangle(0, 0, 100, 100)
Dim junkTex1 As TextureBrush = New TextureBrush(junkSprite, Junk1)
Dim planetRect As Rectangle = New Rectangle(300, 300, 200, 200)
Dim planetCirc As Bitmap = planet.Clone(planetRect, Imaging.PixelFormat.DontCare)
Dim tPlanetGreenBrush As TextureBrush = New TextureBrush(planetCirc)
Dim Junk2 As Rectangle = New Rectangle(100, 0, 100, 100)
Dim junkTex2 As TextureBrush = New TextureBrush(junkSprite, Junk2)
Dim Junk3 As Rectangle = New Rectangle(200, 0, 100, 100)
Dim junkTex3 As TextureBrush = New TextureBrush(junkSprite, Junk3)
Dim Junk4 As Rectangle = New Rectangle(300, 0, 100, 100)
Dim junkTex4 As TextureBrush = New TextureBrush(junkSprite, Junk4)
Dim Junk5 As Rectangle = New Rectangle(0, 100, 100, 100)
Dim junkTex5 As TextureBrush = New TextureBrush(junkSprite, Junk5)
Dim Junk6 As Rectangle = New Rectangle(100, 100, 100, 100)
Dim junkTex6 As TextureBrush = New TextureBrush(junkSprite, Junk6)
Dim Junk7 As Rectangle = New Rectangle(200, 100, 100, 100)
Dim junkTex7 As TextureBrush = New TextureBrush(junkSprite, Junk7)
Dim Junk8 As Rectangle = New Rectangle(300, 100, 100, 100)
Dim junkTex8 As TextureBrush = New TextureBrush(junkSprite, Junk8)
tBrushArray(0) = Nothing
tBrushArray(1) = junkTex1
tBrushArray(2) = junkTex2
tBrushArray(3) = junkTex3
tBrushArray(4) = junkTex4
tBrushArray(5) = junkTex5
tBrushArray(6) = junkTex6
tBrushArray(7) = junkTex7
tBrushArray(8) = junkTex8
tBrushArray(9) = Nothing
tBrushArray(10) = Nothing
tBrushArray(11) = Nothing
tBrushArray(12) = Nothing
tBrushArray(13) = Nothing
tBrushArray(14) = Nothing
tBrushArray(15) = Nothing
tBrushArray(16) = Nothing
tBrushArray(17) = Nothing
tBrushArray(18) = Nothing
tBrushArray(19) = Nothing
End Sub
'The error is being thrown on line 7. This is executed in the onPaint() event.
For a = 0 To 4
Dim imageID As Int16 = Junk(a, 0)
If Junk(a, 0) > 0 Then
junkSprite.MakeTransparent(Color.Fuchsia)
g.Graphics.FillRectangle(tBrushArray(imageID), tJunk(a))
End If
Next
Any help or suggestions would be welcomed.