473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2807
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Maarten | last post by:
Does anyone can help with this? For our goose game, we have to create the game board in a spiral. It may be a square instead of an oval or circle. Does anyone know a simple formula to do this...
0
by: Supra | last post by:
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...
0
by: Supra | last post by:
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...
2
by: tshad | last post by:
I have an aspx window that is going to open a window (javascript) and display a graphic. I want to resize the window to the size of the graphic before it actually displays - how do I do that? ...
10
by: sam_cit | last post by:
Hi Everyone, I'm working on developing a chess game and i decided to use c++ for its object oriented approach. I have a bass class unit and is inherited to distinct number of units (like king,...
4
by: Hypnotik | last post by:
So I'm writing this program. I have the board constructed, and I'm having a problem making a move. At this point I just want to make a move, I'll work on whether it is a legal move after that. The...
1
by: enp | last post by:
Hello, I am trying to create a board game in C#. I have looked into several different websites for creating a board for my game but I am unsuccessful. can somebody help me with their suggestion...
1
by: nt5515 | last post by:
hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've...
9
by: ARC | last post by:
Hello all, I developed a tool a year or so ago for adding your own spell-checker to an access application. This is mainly for those using the runtime, as you can't distribute the spell-checker...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.