Custom Color Help? (Solved)
Hi! I'm having trouble setting a custom color for a rectangle. I used a solidbrush to use the color, and brush1 to = solidbrush. This code does not work with e.Graphics.FillRectangle(LBrush, 0, 0, 50, 50). Both ways just give me the form with a huge red x over everything. What is wrong? Thanks!
vb Code:
Public Class Form1
Dim LColor As Color = New Color
Dim LBrush As SolidBrush
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
NewColor()
Me.Invalidate()
End Sub
Private Sub NewColor()
Randomize()
LColor = Color.FromArgb(Math.Round(Rnd() * 150) + 100, Math.Round(Rnd() * 150) + 100, Math.Round(Rnd() * 150) + 100)
LBrush.Color = LColor
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim Brush1 As Brush = LBrush
e.Graphics.FillRectangle(Brush1, 0, 0, 50, 50)
End Sub
End Class
Re: Custom Color Help? (Solved)
When you create any disposable object, make sure that you dispose it when you're done with it. This is usually done with a Using block if possible, e.g.
Code:
Using LBrush As SolidBrush = New SolidBrush(LColor)
e.Graphics.FillRectangle(LBrush, 0, 0, 50, 50)
End Using