G
Galen Somerville
Going from VB6 (RAD) to VB2005 (SAD)
The documentation always shows graphics drawing in a paint event like
Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint
End Sub
But my VB6 program draws to the picturebox PictColor from many different
subs.
Can I draw to PictColor directly from subs as follows:
Here I am drawing pixels
Dim h As Graphics, g As Graphics, p As New Pen(Color.Black)
'Draws the color squares
g = Me.PictColor.CreateGraphics
h = Me.picBW.CreateGraphics
For intNumber0 = 0 To 255
For intNumber1 = 0 To 255
p.Color = Color.FromArgb(intNumber0, 255 - intNumber1, 255 -
intNumber0)
g.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
p.Color = Color.FromArgb(intNumber0, intNumber0, intNumber0)
h.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
Next
Next
Here I am drawing lines
Dim Incr, Index As Short, g As Graphics, p As New Pen(Color.Black), c As
Color
g = Me.PictColor.CreateGraphics
c = Color.FromArgb(mlColors(0))
p.Color = c
Incr = 200 / 5
For Index = 0 To 5 Step 1
g.DrawLine(p, X1, Y1, X2, Y2)
X1 = X1 + Incr
If Index = 4 Then X1 = X1 - 1
X2 = X1
Next Index
Or do I have to make a cajillion different Paint events for PictColor ??
If I can do it outside of Paint events, can I declare the CreateGraphics
once after Form load ??
GalenS
The documentation always shows graphics drawing in a paint event like
Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint
End Sub
But my VB6 program draws to the picturebox PictColor from many different
subs.
Can I draw to PictColor directly from subs as follows:
Here I am drawing pixels
Dim h As Graphics, g As Graphics, p As New Pen(Color.Black)
'Draws the color squares
g = Me.PictColor.CreateGraphics
h = Me.picBW.CreateGraphics
For intNumber0 = 0 To 255
For intNumber1 = 0 To 255
p.Color = Color.FromArgb(intNumber0, 255 - intNumber1, 255 -
intNumber0)
g.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
p.Color = Color.FromArgb(intNumber0, intNumber0, intNumber0)
h.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
Next
Next
Here I am drawing lines
Dim Incr, Index As Short, g As Graphics, p As New Pen(Color.Black), c As
Color
g = Me.PictColor.CreateGraphics
c = Color.FromArgb(mlColors(0))
p.Color = c
Incr = 200 / 5
For Index = 0 To 5 Step 1
g.DrawLine(p, X1, Y1, X2, Y2)
X1 = X1 + Incr
If Index = 4 Then X1 = X1 - 1
X2 = X1
Next Index
Or do I have to make a cajillion different Paint events for PictColor ??
If I can do it outside of Paint events, can I declare the CreateGraphics
once after Form load ??
GalenS