graphic window checker board game......

S

Supra

i got board working using graphic window in vb.net but no controls
adding to form. i am doing checker board game. when i clicked and moved
the peg to another location(grid). but how do i get bitmap or image to
make invisible.

here is code for mouseevent:

Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
Me.PegPicking = True
If Me.PegPicking = True Then
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
DrawingUtility.DrawPeg(g, New Rectangle(Me.mPosition.X
- 15, Me.mPosition.Y - 15, 30, 30), Me.PelleteColors(0))
g.SmoothingMode = Drawing2D.SmoothingMode.HighSpeed

End If
' Invalidate()
End Sub

Protected Overrides Sub OnMouseMove(ByVal e As
System.Windows.Forms.MouseEventArgs)
' change Position to current mouse Position
Me.mPosition = New Point(e.X, e.Y)
' Repaint to Show Effect
Invalidate()
' End If
End Sub

Protected Overrides Sub OnMouseUp(ByVal e As
System.Windows.Forms.MouseEventArgs)
Me.PegPicking = True
'Inserting Pegs but only is Game is Active
Invalidate()
End Sub

how do i make bitmap or image invisible or something like disappearing?
 
O

One Handed Man \( OHM#\)

I dont really know how you have written this. But one approach might be to
repaint a sqare either with or without the peg, depending on the underlying
matrix properties ( assuming you have coded it like this. )

Regards - OHM
 
S

Supra

can u see my pic? on right side i clicked peg and moved another location
(grid), but b4 i moved peg another location. the peg isn't invisible. i
am using gdi graphic using image. there are no control on form.
ne ideas u can give me an hint?
regards,
supra
 
M

Mick Doherty

Theres no picture attached, but if there were it would not help.
Store the position of pegs in a class level variable.
Do ALL your drawing in the forms Paint method.
In your mouse events, update the position of the current peg and Invalidate
the form, preferably passing a rectangle to the Invalidate call so that only
the relevant part of the form gets painted.
 
S

Supra

here is code for red peg image:
Private Function CreateRedImageSquares() As Image
Dim img As Image
img = New Bitmap(60, 60) 'create square 60 * 60
Dim g As Graphics = Graphics.FromImage(img)
g.Clear(Me.BackColor)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
rb = New Rectangle(1, 1, 150, 150)
Dim sb As New SolidBrush(Color.Red)
g.FillRectangle(sb, rb)
Return img
End Function

Private Sub drawDraughts()
' Create Offscreen Bitmap with width and height equal to
that of Form
OffScreenBitmap = New Bitmap(Me.Width, Me.Height)
g = Graphics.FromImage(OffScreenBitmap)
RedImageSquares = Me.CreateRedImageSquares
BlackImageSquare = Me.CreateBlackImageSquares
PegImages = CreatePegImages(2)
End Sub

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
 
L

Larry Serflaten

Supra said:
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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x, y As Integer
' Create checkerboard
Graphics.FromImage(Board).Clear(Color.White)
For y = 0 To 7
For x = 0 To 7
DrawSquare(x, y)
Next
Next
Me.BackgroundImage = Board
End Sub

Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
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(Mouse) ' Draw old position
Mouse = New Point(X, Y)
DrawSquare(Mouse, Color.Yellow) ' Draw new pos.
Me.Invalidate()
End If
End Sub

Private Sub DrawSquare(ByVal Mouse As Point)
DrawSquare(Mouse.X, Mouse.Y)
End Sub

Private Sub DrawSquare(ByVal Mouse As Point, ByVal Kolor As Color)
DrawSquare(Mouse.X, Mouse.Y, Kolor)
End Sub

Private Sub DrawSquare(ByVal 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(ByVal X As Integer, ByVal Y As Integer, ByVal Kolor As Color)
' Draws a single square
Dim gr As Graphics = Graphics.FromImage(Board)
Dim br As Brush = New SolidBrush(Kolor)
Dim rct As Rectangle = New Rectangle(X * SS, Y * SS, SS, SS)
gr.FillRectangle(br, rct)
gr.DrawRectangle(Pens.Black, rct)
br.Dispose()
gr.Dispose()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top