in ludo game i got 4 images on board. if i clicked first image then i
wanted first images be delete or invisible or whatever and place another
location and so on. how do i delete first images?..... u may copy and
paste it.
Private OffScreenBitmap As Bitmap
Private g As Graphics
Private rb As Rectangle
Dim Startpoint As Point = New Point(5, 10)
'Defines position and size each element of board
Dim Boxes(,) As Rectangle = New Rectangle(11, 4) {}
' defines Position and size of each Pegs available.
Dim ColorPellete() As Rectangle
'selected any colours
Private PelleteColors As Color() = New Color() {Color.Purple,
Color.Blue, Color.Green, Color.Red}
'Images for boxex images
Private PegImages() As Image
Dim BoxWidth As Integer = 24
Dim Border As Integer = 5
Private i, j, x As Integer
Private Sub CreateOffSetScreenImage()
g.Clear(Me.BackColor)
Dim pn As New Pen(Color.Blue, 5)
For i = 0 To PelleteColors.Length - 1
g.DrawImage(Me.PegImages(i), ColorPellete(i).X + 65,
ColorPellete(i).Y + 105)
Next i
End Sub
Protected Overrides Sub OnPaintBackground(ByVal pevent As
System.Windows.Forms.PaintEventArgs)
'do nothing. this will stop flicking due do background Drawing.
End Sub
Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
'if User is Draging peg no need to reDraw Image
If PegPicking = False Then
CreateOffSetScreenImage()
End If
'Get Graphics Object from EventArgs.Graphics
Dim gf As Graphics = e.Graphics
'Draw OffScreen Image to Screen
gf.DrawImage(Me.OffScreenBitmap, 0, 0, New Rectangle(0, 0,
Me.Width, Me.Height), GraphicsUnit.Pixel)
End Sub
Private Sub drawLudo()
' Create Offscreen Bitmap with width and height equal to
that of Form
OffScreenBitmap = New Bitmap(Me.Width, Me.Height)
g = Graphics.FromImage(OffScreenBitmap)
'UpperLeftCornerBoxImages =
Me.CreateUpperLeftImageSquaresCorner()
ColorPellete = PelleteRectangles(CByte((4)), New Point(20, 20))
PegImages = CreatePegImages(4)
End Sub
Private Function PelleteRectangles(ByVal b As Byte, ByVal p As
Point) As Rectangle()
Dim r() As Rectangle = New Rectangle(b) {}
For i = 1 To b
If Decimal.Remainder(i, 2) = 1 Then
r(i - 1) = New Rectangle(p.X + Border - 10,
CInt((p.Y + Border + Math.Floor((i - 1) / 2) * 50)), BoxWidth, BoxWidth)
Else
r(i - 1) = New Rectangle(p.X + Border * 2 + BoxWidth
+ 20, CInt((p.Y + Border + ((i - 2) / 2) * 50)), BoxWidth, BoxWidth)
End If
Next
Return r
End Function
Private Function CreatePegImages(ByVal pelleteSize As Byte) As
Image()
Dim pegImages() As Image = New Image(pelleteSize + 1) {}
For i = 0 To pelleteSize - 1
pegImages(i) = New Bitmap(40, 40)
Dim g As Graphics = Graphics.FromImage(pegImages(i))
g.Clear(Color.White)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
DrawingUtility.DrawPeg(g, New Rectangle(5, 5, 30, 30),
PelleteColors(i))
g.Dispose()
Next
Return pegImages
End Function
' Mouse position while Draging.
Dim mPosition As Point = New Point(0, 0)
' true if user is draging peg to board.
Dim PegPicking As Boolean = False
Public SelectedPeg As Byte = 255
Protected Overrides Sub OnMouseDown(ByVal e As
System.Windows.Forms.MouseEventArgs)
Me.PegPicking = True
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As
System.Windows.Forms.MouseEventArgs)
Me.PegPicking = True
g.DrawImage(Me.PegImages(0), ColorPellete(0).X + e.X,
ColorPellete(0).Y + e.Y)
Invalidate()
End Sub
regards