Hello, Mark,
You could use the FromArgb method, as in the example below (that sets
the background color of a form containing a button):
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Dim RedValue As Integer = 255 * Rnd()
Dim GreenValue As Integer = 255 * Rnd()
Rnd() is old vb, try the random class:
Public Class Form1
Private randomGenerator As Random
Private WithEvents t As Timer
Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
randomGenerator = New Random
t = New Timer
t.Interval = 50
t.Start()
End Sub
Private Sub t_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles t.Tick
' trigger paint
Me.Invalidate()
End Sub
Private Function randomColor() As Color
' array to hold 3 bytes
Dim rgb(2) As Byte
' fill the array with random bytes
randomGenerator.NextBytes(rgb)
' return a new color
Return Color.FromArgb(rgb(0), rgb(1), rgb(2))
End Function
Private Function randomPoint() As Point
Dim x As Integer = randomGenerator.Next(0, Me.ClientSize.Width +
1)
Dim y As Integer = randomGenerator.Next(0, Me.ClientSize.Height +
1)
Return New Point(x, y)
End Function
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(New Pen(randomColor), randomPoint,
randomPoint)
End Sub
End Class