"Supra" <su*******@roge rs.com> wrote
the pb is if u clicked peg(mousedown) i wanted that image disappearred
and place another location. but i have red peg on new location.... that
fine, but can't deleteed previously.
another ideas.....if i clicked red peg, get the black colour and paint
over red peg image to make invisible....is that good ideas. but how do i
changed to blk colour?
ne hint u can give me?
regards
Normally I add a Picturebox to the form for drawing, but here, for
demonstration, I just used the BackGroundImage of the form.
Start a new project and paste the code below AFTER the
'Windows Form designer generated code' section. Run the
program and click on the checkerboard to see the yellow
marker mark the square. Of course, instead of a yellow
marker, you could be drawing actual game pieces, or
whatever. Do note that I only create 1 bitmap for the
entire time the form is loaded.
HTH
LFS
Private Const SS As Integer = 40 ' Square Size
Private Board As Bitmap = New Bitmap(360, 360)
Private Color1 As Color = Color.Tomato
Private Color2 As Color = Color.Black
Private Mouse As Point
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
Dim x, y As Integer
' Create checkerboard
Graphics.FromIm age(Board).Clea r(Color.White)
For y = 0 To 7
For x = 0 To 7
DrawSquare(x, y)
Next
Next
Me.BackgroundIm age = Board
End Sub
Private Sub Form1_MouseDown (ByVal sender As Object, ByVal e As System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseDow n
Dim X As Integer = e.X \ SS
Dim Y As Integer = e.Y \ SS
If X < 8 And Y < 8 Then 'Limit to within board
DrawSquare(Mous e) ' Draw old position
Mouse = New Point(X, Y)
DrawSquare(Mous e, Color.Yellow) ' Draw new pos.
Me.Invalidate()
End If
End Sub
Private Sub DrawSquare(ByVa l Mouse As Point)
DrawSquare(Mous e.X, Mouse.Y)
End Sub
Private Sub DrawSquare(ByVa l Mouse As Point, ByVal Kolor As Color)
DrawSquare(Mous e.X, Mouse.Y, Kolor)
End Sub
Private Sub DrawSquare(ByVa l X As Integer, ByVal Y As Integer)
' Default red/black colors
If (Y And 1) = (X And 1) Then
DrawSquare(X, Y, Color1)
Else
DrawSquare(X, Y, Color2)
End If
End Sub
Private Sub DrawSquare(ByVa l X As Integer, ByVal Y As Integer, ByVal Kolor As Color)
' Draws a single square
Dim gr As Graphics = Graphics.FromIm age(Board)
Dim br As Brush = New SolidBrush(Kolo r)
Dim rct As Rectangle = New Rectangle(X * SS, Y * SS, SS, SS)
gr.FillRectangl e(br, rct)
gr.DrawRectangl e(Pens.Black, rct)
br.Dispose()
gr.Dispose()
End Sub