470,596 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

graphic window checker board game......

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?

Nov 20 '05 #1
6 2648
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


"Supra" <su*******@rogers.com> wrote in message
news:Kd************@news04.bloor.is.net.cable.roge rs.com...
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?

Nov 20 '05 #2
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

One Handed Man ( OHM#) wrote:
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


"Supra" <su*******@rogers.com> wrote in message
news:Kd************@news04.bloor.is.net.cable.roge rs.com...
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?



Nov 20 '05 #3
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.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...nate/home.html
"Supra" <su*******@rogers.com> wrote in message
news:iX*******************@twister01.bloor.is.net. cable.rogers.com...
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

One Handed Man ( OHM#) wrote:
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


"Supra" <su*******@rogers.com> wrote in message
news:Kd************@news04.bloor.is.net.cable.roge rs.com...
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?


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Nov 20 '05 #4

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

Mick Doherty wrote:
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.


Nov 20 '05 #5

"Supra" <su*******@rogers.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(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
Nov 20 '05 #6
thank! i c u have drawsquare overloaded.
regards,

Larry Serflaten wrote:
"Supra" <su*******@rogers.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(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


Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Maarten | last post: by
reply views Thread by Supra | last post: by
10 posts views Thread by sam_cit | last post: by
4 posts views Thread by Hypnotik | last post: by
1 post views Thread by enp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.