Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. MouseDown Event? [modified]

MouseDown Event? [modified]

Scheduled Pinned Locked Moved C#
helpquestionlearning
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Megidolaon
    wrote on last edited by
    #1

    In the past I had trouble with a PictureBoxes MouseUp event, but that fixed itself and never got an issue afterwards. Now another of its events is causign me headaches. MouseDown should occur when the cursor is above the control while a mouse button is held down, right? So, selecting multiple cells in Excel uses the same principle or? My problem is that I have a lot of PictureBoxes directly next to each other and with the MouseDown event I wanted the user to select multiple PictureBoxes. Yet, it gets fired only once for the first time you click and hold a mouse button, it should get fired every time you select another PictureBox, but it only gets fired again after releasing the mouse button and pressing it again. Of course, that makes selection impossible. Could anyone tell me what went wrong and how can fix it? I'm trying to achieve the same effect with the MouseHover event, but that will be a makeshift solution at best. EDIT: Scrap that part with the MouseHover event, that doesn't ever fire.

    modified on Wednesday, May 6, 2009 5:32 AM

    A OriginalGriffO U 3 Replies Last reply
    0
    • M Megidolaon

      In the past I had trouble with a PictureBoxes MouseUp event, but that fixed itself and never got an issue afterwards. Now another of its events is causign me headaches. MouseDown should occur when the cursor is above the control while a mouse button is held down, right? So, selecting multiple cells in Excel uses the same principle or? My problem is that I have a lot of PictureBoxes directly next to each other and with the MouseDown event I wanted the user to select multiple PictureBoxes. Yet, it gets fired only once for the first time you click and hold a mouse button, it should get fired every time you select another PictureBox, but it only gets fired again after releasing the mouse button and pressing it again. Of course, that makes selection impossible. Could anyone tell me what went wrong and how can fix it? I'm trying to achieve the same effect with the MouseHover event, but that will be a makeshift solution at best. EDIT: Scrap that part with the MouseHover event, that doesn't ever fire.

      modified on Wednesday, May 6, 2009 5:32 AM

      A Offline
      A Offline
      Alex UEA
      wrote on last edited by
      #2

      could you indicate that each picture box has been selected by highlighting in some way when it is clicked (and released). Clicking it again would unselect it. Then when selection of all boxes is complete itterate through picture boxes and if highlighted/selected do whatever it is you want to do? I guess that involves a selection stage and then an action upon the selected stage rather than happening all in one as I think you wanted

      1 Reply Last reply
      0
      • M Megidolaon

        In the past I had trouble with a PictureBoxes MouseUp event, but that fixed itself and never got an issue afterwards. Now another of its events is causign me headaches. MouseDown should occur when the cursor is above the control while a mouse button is held down, right? So, selecting multiple cells in Excel uses the same principle or? My problem is that I have a lot of PictureBoxes directly next to each other and with the MouseDown event I wanted the user to select multiple PictureBoxes. Yet, it gets fired only once for the first time you click and hold a mouse button, it should get fired every time you select another PictureBox, but it only gets fired again after releasing the mouse button and pressing it again. Of course, that makes selection impossible. Could anyone tell me what went wrong and how can fix it? I'm trying to achieve the same effect with the MouseHover event, but that will be a makeshift solution at best. EDIT: Scrap that part with the MouseHover event, that doesn't ever fire.

        modified on Wednesday, May 6, 2009 5:32 AM

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Megidolaon wrote:

        MouseDown should occur when the cursor is above the control while a mouse button is held down, right?

        Wrong. Mouse down happens when "the mouse pointer is over a control and the mouse button is pressed" - definition from MS. What this means is that when the mouse button is pressed down, a single event is fired and sent to the control the mouse pointer is over at the time. If it did what you thought, you would get a continuous stream of MouseDown events, which is not what is wanted in most cases. Most people need one MouseDown, one MouseUp. What you need is MouseDown and then MouseMove (possibly with MouseCapture thrown in for goodmeasure)

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        M 1 Reply Last reply
        0
        • M Megidolaon

          In the past I had trouble with a PictureBoxes MouseUp event, but that fixed itself and never got an issue afterwards. Now another of its events is causign me headaches. MouseDown should occur when the cursor is above the control while a mouse button is held down, right? So, selecting multiple cells in Excel uses the same principle or? My problem is that I have a lot of PictureBoxes directly next to each other and with the MouseDown event I wanted the user to select multiple PictureBoxes. Yet, it gets fired only once for the first time you click and hold a mouse button, it should get fired every time you select another PictureBox, but it only gets fired again after releasing the mouse button and pressing it again. Of course, that makes selection impossible. Could anyone tell me what went wrong and how can fix it? I'm trying to achieve the same effect with the MouseHover event, but that will be a makeshift solution at best. EDIT: Scrap that part with the MouseHover event, that doesn't ever fire.

          modified on Wednesday, May 6, 2009 5:32 AM

          U Offline
          U Offline
          User 304437
          wrote on last edited by
          #4

          It sounds like what you are trying to do may be accomplished better by using the same techniques as for drag-n-drop. Your current approach will only trigger a single mouse-down event so what you will need to do is get the "point" (x,y) position during the mouse down, track the mouse move event and get the "point" (x,y) position at the time of the mouse-up event. Of course this requires you to determine which picture boxes fall within the selection buy comparing their locations.

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Megidolaon wrote:

            MouseDown should occur when the cursor is above the control while a mouse button is held down, right?

            Wrong. Mouse down happens when "the mouse pointer is over a control and the mouse button is pressed" - definition from MS. What this means is that when the mouse button is pressed down, a single event is fired and sent to the control the mouse pointer is over at the time. If it did what you thought, you would get a continuous stream of MouseDown events, which is not what is wanted in most cases. Most people need one MouseDown, one MouseUp. What you need is MouseDown and then MouseMove (possibly with MouseCapture thrown in for goodmeasure)

            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

            M Offline
            M Offline
            Megidolaon
            wrote on last edited by
            #5

            Nah, MouseMove fires the moment you move the mouse, so moving it around over one and the same PictureBox firest it countless times. I realized MouseHover would do the same and MouseEnter is what I need. But that event doesn't fire when the mouse button is held down, so it's of no use to me. I tried catching mouse coordinates before, but they do not correspond to control sizes and I displayed the coordinates when the mouse triggered and event of one a control, but the X coordinate was about 200 higher than the width of that control (which started at the left edge, so the rightcoordinates should have been at most 5 more than the width). And debugging that is hell, because during if you set set a breakpoint, coordinates will change to wherever the mouse currently is, even if it's not in your application anymore but in VS.

            OriginalGriffO 1 Reply Last reply
            0
            • M Megidolaon

              Nah, MouseMove fires the moment you move the mouse, so moving it around over one and the same PictureBox firest it countless times. I realized MouseHover would do the same and MouseEnter is what I need. But that event doesn't fire when the mouse button is held down, so it's of no use to me. I tried catching mouse coordinates before, but they do not correspond to control sizes and I displayed the coordinates when the mouse triggered and event of one a control, but the X coordinate was about 200 higher than the width of that control (which started at the left edge, so the rightcoordinates should have been at most 5 more than the width). And debugging that is hell, because during if you set set a breakpoint, coordinates will change to wherever the mouse currently is, even if it's not in your application anymore but in VS.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Yes, thats the whole idea. You get a Mouse Down, and start tracking the mouse. You can then follow (and select) all the images you wish until you get the MouseUp. The only other way to do the multiple selections is via Control + MouseDown, or Shift and MouseDown - which does not sound like what you want. I seriously would not consider breakpointing MouseMove! As a sugestion, set up a form with your images in it, and use Spy++ to examine the mouse messages as you perform the actions you want to do the selections. This should give you a good idea of the message flow you can expect, and you can then see how to handle them.

              No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups