Results 1 to 11 of 11

Thread: Why is mouse up ignored ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,426

    Why is mouse up ignored ?

    Hi,

    I don't understand what's happening here.
    Code:
                    Me.Controls.Add(pbx) ' Add twenty Pictureboxes.
                    AddHandler pbx.MouseUp, AddressOf CatchUp
                    If Form3.Button4.BackColor = Color.Green Then
                        AddHandler pbx.MouseDown, AddressOf EnterPicDrag
                        AddHandler pbx.DragEnter, AddressOf DragPics
                        AddHandler pbx.GiveFeedback, AddressOf PBGF
                    Else
                        AddHandler pbx.MouseClick, AddressOf ClikPic
                        AddHandler pbx.MouseDown, AddressOf EnterPic
                    End If
    Also
    Code:
        Private Sub CatchUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
            Beep()
        End Sub
    
        Private Sub EnterPic(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
            Beep()
        End Sub
    
        Private Sub EnterPicDrag(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
            Beep()
        End Sub
    With the cursor in (any) pbx and depress the mouse button (either button, makes no difference)... 'Beep'.
    Release the button (when Form3.Button4.BackColor is Green)... 'Beep'
    Release the button (when Form3.Button4.BackColor is NOT Green)... Nothing happens... Why not ?


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,466

    Re: Why is mouse up ignored ?

    Using beep, is a poor choice for debugging. Use your immediate window - Debug.Print(“a unique useful identifying message”)

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Why is mouse up ignored ?

    It looks like you are doing drag and drop. Once you start into drag and drop, the behavior of some events tends to change. I don't remember the exact details, but I know that some events, such as MouseHover (or something like that) don't occur when you are in a drag, so MouseUp may be just another thing. You wouldn't be using MouseUp as part of a drag action anyways, so if you were intending that, then you're on the wrong track there. You want the DragDrop event for that, which is raised by the target of the drop.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,426

    Re: Why is mouse up ignored ?

    Quote Originally Posted by Shaggy Hiker View Post
    It looks like you are doing drag and drop. Once you start into drag and drop, the behavior of some events tends to change. I don't remember the exact details, but I know that some events, such as MouseHover (or something like that) don't occur when you are in a drag, so MouseUp may be just another thing. You wouldn't be using MouseUp as part of a drag action anyways, so if you were intending that, then you're on the wrong track there. You want the DragDrop event for that, which is raised by the target of the drop.
    Thanks for the reply .Paul and Shaggy,
    Yes, I'm using drag (but not drop). I have a game which I play quite often, I used to enjoy 'Minesweeper' which shipped with a lot of the early Windows OS, I suspect it was an exercise to teach mouse expertise. Anyway, I like this game, but with today's screen resolution it's too fiddly to play without resetting the resolution right down, so I wrote my own version. I didn't want to get into recursion so, where in the original game clicking on an empty square would expose all the empty squares in the region, in my game you have to click 'em all.
    However, to make up for that, holding the mouse button down I can 'drag' the cursor over the squares without actually having to click each individual one. Left mouse step on square, right button to mark a mine. Step on a mine... Game over.
    There is an option not to use drag, (Button4 not green), and in that mode, should I realise I've left clicked where I meant to right click, if I realise it before I release the button, I can 'slide' into another square before releasing it and no harm done. I can't do that in drag mode, so I'm trying to employ a timer... keep the cursor still, wait for the timer to correct the error (say 2 seconds).
    I can get the timer to start on mouse down, but I can't get it to stop on mouse up... I haven't even got as far as stopping it and starting it again when I change squares (PictureBoxes).
    Beep was quick and easy.

    Poppa
    Along with the sunshine there has to be a little rain sometime.

  5. #5
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Why is mouse up ignored ?

    Not an answer to your question directly, but when I wrote a version of Minesweeper a long time ago, what I did for the "mass uncover" process when you click a box with 0 neighboring mines is this:

    Have an l x w 2d array that represents each square on the board.
    Since I've uncovered the box in position say x, y, mark all neighboring squares as "to be uncovered", if appropriate (taking edges and already marked mines into account, boxes already uncovered, etc.)
    Call the MassUncover Sub that loops through all boxes on the board.
    MassUncover sub is basically this pseudocode:

    Code:
    ToUncover = True
    Do While ToUncover = True
      ToUncover = False
      For i = 1 to l
        For j = 1 to w
          If arrUncover(i, j) = 1 Then 'Box is marked as to be uncovered
            If arrBoard(i, j) = 0 Then 'This means the box to uncover also has no neighboring mines, so mark its adjacent boxes as to be uncovered
              'Code to Mark adjacent boxes as to be uncovered if appropriate (same restrictions as noted above)
              arrUncover(i-1, j-1) = 1 ' Upper-left box
              arrUncover(i, j-1) = 1 ' Above box
              ...and so on
              ToUncover = True
            End If
            'Show contents of board at position i, j
          End If
        Next j
      Next i
    Loop
    It isn't recursive, it loops until no boxes need to be uncovered because of a mass reveal.

    Good luck
    Last edited by OptionBase1; Apr 29th, 2021 at 05:59 PM.

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: Why is mouse up ignored ?

    For the sake of clarity, this was the main idea behind the board of my implementation:

    arrBoard(length, width)
    2d array that represents each box on the board.
    A value of -1 means that that box has a mine
    Values of 0-8 mean that box has 0-8 neighboring mines

    arrUncover(length, width)
    2d array that represents each box on the board.
    Values:
    0 - this box has not been uncovered and is not marked as a mine
    1 - this box needs to be mass uncovered
    2 - this box has already been uncovered
    3 - this box has been flagged as a mine

    I didn't implement the intermediate "?" marking that Windows Minesweeper has, just toggled between marked as a mine or unmarked.

    Good luck.
    Last edited by OptionBase1; Apr 29th, 2021 at 06:29 PM.

  7. #7

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,426

    Re: Why is mouse up ignored ?

    Quote Originally Posted by OptionBase1 View Post
    I didn't implement the intermediate "?" marking that Windows Minesweeper has, just toggled between marked as a mine or unmarked.
    Good luck.
    Thanks OB1

    I have it so that if a square which is marked as a mine is 'Right Clicked' again, it will have the '?' mark, and if it's 'Right Clicked' yet again it will revert to 'Unknown'. This follows the original game play. It's handy for when I can't choose between two or more squares.

    Unlike the original game, I use a 'Mine Field' I also have a choice of cursors... a little bayonet (arrow) or a metal detector (ring). Sadly, I don't guarantee that the game can be solved by logic alone, I frequently get down to two squares with just one mine to find and generally choose the wrong one.

    Poppa

    PS
    Just in case you're interested it's in the cloud at: https://1drv.ms/u/s!Aq35f8WRsvGjgaEX...KBM9w?e=8OlG8O
    Pop.
    Last edited by Poppa Mintin; Apr 29th, 2021 at 07:01 PM. Reason: PS Added
    Along with the sunshine there has to be a little rain sometime.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Why is mouse up ignored ?

    If you start with drag, I think you'll have to end with it. The sequence of events fired on mouse actions is the same (roughly), but the events themselves are not the same. For example, one of the events (MouseOver or MouseMove, or something like that) doesn't get raised as long as you have started a drag action, but there is a second event that you can use in place of it (which I also don't remember, and don't feel like looking up, at the moment). I believe that the same is true of MouseUp. DragDrop is the drag action alternative. You don't have to DO anything much different from what you'd be doing in MouseUp, but you need to do that in the DragDrop event handler. You get whatever you want as the payload that comes with the event, which is different from MouseUp, and the object that raises the event is different (it's the drop target), but it's conceptually the same thing. Dropping is done by releasing the mouse button, so DragDrop becomes the MouseUp event, just with a few differences.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,426

    Re: Why is mouse up ignored ?

    Thanks Shaggy,

    I've found DragDrop and it works as you describe.
    I can get the timer to start and stop at the right times, trouble is... I can't work out how to use 'em without interrupting the drag.
    I need to figure out how when dragging, to wait until the cursor has entered the next PictureBox (or the mouse is released) before servicing the previous one, even then I think that that would disrupt the natural flow.

    I may have to consider only starting the timer on the first 'click' of a drag, that's when I usually hit the wrong button anyway, although sometimes I get a bit careless when I'm dragging, especially considering that the 'mouse mat' is usually the arm of the sofa.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Why is mouse up ignored ?

    Look into DragOver, it's the Drag and Drop analogue to MouseMove (more or less). You know which PB the cursor was in when you started the drag, since that's where you started the drag, and DragOver looks like it is raised by whatever you are over at the moment. I've used it to check what is under the mouse during a drag, but in my case, the dragging and dropping was all within the same control, so you may find some surprises.
    My usual boring signature: Nothing

  11. #11

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,426

    Re: Why is mouse up ignored ?

    Thanks Shaggy,

    I've found DragOver and it has great possibilities. It's 01.59 here so I'm off to bed, currently though:
    1. I no longer need a timer.
    2. While ever the mouse is down, DragOver continues to be triggered.
    3. I can detect which 'Box' the cursor is in and I count the iterations of DragOver and when it reaches (currently) 40 it sets a Boolean which will trigger what ever I'm going to do to cancel the error.
    4. If the mouse changes boxes the counter resets to zero but continues counting.
    5. Releasing the mouse resets the counter to zero, and resets the Boolean if it's set.

    More fun tomorrow.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width