graphic window checker board game......

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Supra

    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(ByV al e As
    System.Windows. Forms.MouseEven tArgs)
    Me.PegPicking = True
    If Me.PegPicking = True Then
    g.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
    DrawingUtility. DrawPeg(g, New Rectangle(Me.mP osition.X
    - 15, Me.mPosition.Y - 15, 30, 30), Me.PelleteColor s(0))
    g.SmoothingMode = Drawing2D.Smoot hingMode.HighSp eed

    End If
    ' Invalidate()
    End Sub

    Protected Overrides Sub OnMouseMove(ByV al e As
    System.Windows. Forms.MouseEven tArgs)
    ' 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.MouseEven tArgs)
    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?

  • One Handed Man \( OHM#\)

    #2
    Re: graphic window checker board game......

    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" <supra5656@roge rs.com> wrote in message
    news:KdByc.9$A_ 21.8@news04.blo or.is.net.cable .rogers.com...[color=blue]
    > 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(ByV al e As
    > System.Windows. Forms.MouseEven tArgs)
    > Me.PegPicking = True
    > If Me.PegPicking = True Then
    > g.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
    > DrawingUtility. DrawPeg(g, New Rectangle(Me.mP osition.X
    > - 15, Me.mPosition.Y - 15, 30, 30), Me.PelleteColor s(0))
    > g.SmoothingMode = Drawing2D.Smoot hingMode.HighSp eed
    >
    > End If
    > ' Invalidate()
    > End Sub
    >
    > Protected Overrides Sub OnMouseMove(ByV al e As
    > System.Windows. Forms.MouseEven tArgs)
    > ' 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.MouseEven tArgs)
    > 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?
    >[/color]


    Comment

    • Supra

      #3
      Re: graphic window checker board game......

      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:[color=blue]
      > 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" <supra5656@roge rs.com> wrote in message
      > news:KdByc.9$A_ 21.8@news04.blo or.is.net.cable .rogers.com...
      >[color=green]
      >>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(ByV al e As
      >>System.Window s.Forms.MouseEv entArgs)
      >> Me.PegPicking = True
      >> If Me.PegPicking = True Then
      >> g.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
      >> DrawingUtility. DrawPeg(g, New Rectangle(Me.mP osition.X
      >>- 15, Me.mPosition.Y - 15, 30, 30), Me.PelleteColor s(0))
      >> g.SmoothingMode = Drawing2D.Smoot hingMode.HighSp eed
      >>
      >> End If
      >> ' Invalidate()
      >> End Sub
      >>
      >> Protected Overrides Sub OnMouseMove(ByV al e As
      >>System.Window s.Forms.MouseEv entArgs)
      >> ' 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.Window s.Forms.MouseEv entArgs)
      >> 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?
      >>[/color]
      >
      >
      >[/color]

      Comment

      • Mick Doherty

        #4
        Re: graphic window checker board game......

        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



        "Supra" <supra5656@roge rs.com> wrote in message
        news:iXVyc.2251 47$Ar.11282@twi ster01.bloor.is .net.cable.roge rs.com...[color=blue]
        > 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:[color=green]
        > > I dont really know how you have written this. But one approach might be[/color][/color]
        to[color=blue][color=green]
        > > repaint a sqare either with or without the peg, depending on the[/color][/color]
        underlying[color=blue][color=green]
        > > matrix properties ( assuming you have coded it like this. )
        > >
        > > Regards - OHM
        > >
        > >
        > >
        > >
        > > "Supra" <supra5656@roge rs.com> wrote in message
        > > news:KdByc.9$A_ 21.8@news04.blo or.is.net.cable .rogers.com...
        > >[color=darkred]
        > >>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(ByV al e As
        > >>System.Window s.Forms.MouseEv entArgs)
        > >> Me.PegPicking = True
        > >> If Me.PegPicking = True Then
        > >> g.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
        > >> DrawingUtility. DrawPeg(g, New Rectangle(Me.mP osition.X
        > >>- 15, Me.mPosition.Y - 15, 30, 30), Me.PelleteColor s(0))
        > >> g.SmoothingMode = Drawing2D.Smoot hingMode.HighSp eed
        > >>
        > >> End If
        > >> ' Invalidate()
        > >> End Sub
        > >>
        > >> Protected Overrides Sub OnMouseMove(ByV al e As
        > >>System.Window s.Forms.MouseEv entArgs)
        > >> ' 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.Window s.Forms.MouseEv entArgs)
        > >> 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?
        > >>[/color]
        > >
        > >
        > >[/color]
        >[/color]


        ---
        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


        Comment

        • Supra

          #5
          Re: graphic window checker board game......


          here is code for red peg image:
          Private Function CreateRedImageS quares() As Image
          Dim img As Image
          img = New Bitmap(60, 60) 'create square 60 * 60
          Dim g As Graphics = Graphics.FromIm age(img)
          g.Clear(Me.Back Color)
          g.SmoothingMode = Drawing2D.Smoot hingMode.AntiAl ias
          rb = New Rectangle(1, 1, 150, 150)
          Dim sb As New SolidBrush(Colo r.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.FromIm age(OffScreenBi tmap)
          RedImageSquares = Me.CreateRedIma geSquares
          BlackImageSquar e = Me.CreateBlackI mageSquares
          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:[color=blue]
          > 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.
          >[/color]

          Comment

          • Larry Serflaten

            #6
            Re: graphic window checker board game......


            "Supra" <supra5656@roge rs.com> wrote
            [color=blue]
            > 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[/color]


            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


            Comment

            • Supra

              #7
              Re: graphic window checker board game......

              thank! i c u have drawsquare overloaded.
              regards,

              Larry Serflaten wrote:[color=blue]
              > "Supra" <supra5656@roge rs.com> wrote
              >
              >[color=green]
              >>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[/color]
              >
              >
              >
              > 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
              >
              >[/color]

              Comment

              Working...