Mouse Rt and Left click controls

Any good resources on mouse control programming for VB??

I am writing a minesweeper game and trying to do the code for rt. click down to "show" the grid box(control array 1 to 64. and left click to place a flag in the grid position. Also use the left mouse to clear the flag out if there is alreay a flag in the square on the grid??

Any suggestions or direction??

Thanks.

Very new to VB and struggling on this.



Comments

  • : Any good resources on mouse control programming for VB??
    :
    : I am writing a minesweeper game and trying to do the code for rt. click down to "show" the grid box(control array 1 to 64. and left click to place a flag in the grid position. Also use the left mouse to clear the flag out if there is alreay a flag in the square on the grid??
    :
    : Any suggestions or direction??
    :
    : Thanks.
    :
    : Very new to VB and struggling on this.
    :
    :
    [code]
    Dim mouse As MouseButtonConstants

    If mouse = vbRightButton Then
    'your code for the array
    ElseIf mouse = vbLeftButton Then
    'flag code
    ElseIf mouse = vbMiddleButton Then
    'just incase you want to use the middle mouse button
    End If
    [/code]
    :
    :

  • that code has to go int the mouse down event of the control
  • : Any good resources on mouse control programming for VB??
    :
    : I am writing a minesweeper game and trying to do the code for rt. click down to "show" the grid box(control array 1 to 64. and left click to place a flag in the grid position. Also use the left mouse to clear the flag out if there is alreay a flag in the square on the grid??
    :
    : Any suggestions or direction??
    :
    : Thanks.
    :
    : Very new to VB and struggling on this.

    Assuming a image array:
    [code]
    Private Sub Image1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

    Static Flags(0 To 63) As Boolean
    Select Case Button
    Case vbLeftButton
    If Not Flags(Index) Then
    'Clear image if square is not marked
    End If
    Case vbRightButton
    Flags(Index) = Not Flags(Index)
    If Flags(Index) Then
    'Show flag
    Else
    'Hide Flag
    End If
    End Select

    End Sub
    [/code]
    You may want a bit more checking to ignore all clicks if the spot is already cleared, but this should get you started.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories