|
Private dRaster As Single = 46
Private rows As Integer = 8
Private cols As Integer = 8
Private PicBackCol As Color
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
BrettZeichnen(e)
End Sub
Private Sub BrettZeichnen(ByVal e As _
System.Windows.Forms.PaintEventArgs)
Dim i, j As Integer
For j = 0 To rows - 1
If Not (j Mod 2 = 0) Then
For i = 1 To cols - 1 Step 2
Dim x As Integer = CInt(i * dRaster)
Dim y As Integer = CInt(j * dRaster)
Dim w As Integer = CInt(i * dRaster + dRaster) - x
Dim h As Integer = CInt(j * dRaster + dRaster) - y
Dim rect As Rectangle = New Rectangle(x, y, w, h)
Dim oBrush As New SolidBrush(Color.White)
e.Graphics.FillRectangle(oBrush, rect)
Next i
Else
For i = 0 To cols - 1 Step 2
Dim x As Integer = CInt(i * dRaster)
Dim y As Integer = CInt(j * dRaster)
Dim w As Integer = CInt(i * dRaster + dRaster) - x
Dim h As Integer = CInt(j * dRaster + dRaster) - y
Dim rect As Rectangle = New Rectangle(x, y, w, h)
Dim oBrush As New SolidBrush(Color.White)
e.Graphics.FillRectangle(oBrush, rect)
Next i
End If
Next j
For i = 0 To cols
e.Graphics.DrawLine(New Pen(Color.Black, 1), i * dRaster, 0, _
i * dRaster, rows * dRaster)
Next i
For i = 0 To rows
e.Graphics.DrawLine(New Pen(Color.Black, 1), 0, i * dRaster, _
cols * dRaster, i * dRaster)
Next i
End Sub
Private Sub NeuZeichnen()
PictureBox1.BackColor = PicBackCol
rows = CInt(NumericUpDown1.Value)
cols = CInt(NumericUpDown2.Value)
dRaster = NumericUpDown3.Value
PictureBox1.Width = CInt(cols * dRaster + 1)
PictureBox1.Height = CInt(rows * dRaster + 1)
PictureBox1.Invalidate()
End Sub
Private Function ChooseColor() As Color
Dim ColorDialog1 As New ColorDialog
If ColorDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Return ColorDialog1.Color
Else
Return PictureBox1.BackColor
End If
End Function
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
NeuZeichnen()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
NeuZeichnen()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
PicBackCol = ChooseColor()
Button1.Focus()
NeuZeichnen()
End Sub
|
|