MouseDown Event? [modified]
-
In the past I had trouble with a
PictureBox
es 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 ofPictureBox
es directly next to each other and with theMouseDown
event I wanted the user to select multiplePictureBox
es. 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 anotherPictureBox
, 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 theMouseHover
event, but that will be a makeshift solution at best. EDIT: Scrap that part with theMouseHover
event, that doesn't ever fire.modified on Wednesday, May 6, 2009 5:32 AM
-
In the past I had trouble with a
PictureBox
es 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 ofPictureBox
es directly next to each other and with theMouseDown
event I wanted the user to select multiplePictureBox
es. 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 anotherPictureBox
, 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 theMouseHover
event, but that will be a makeshift solution at best. EDIT: Scrap that part with theMouseHover
event, that doesn't ever fire.modified on Wednesday, May 6, 2009 5:32 AM
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
-
In the past I had trouble with a
PictureBox
es 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 ofPictureBox
es directly next to each other and with theMouseDown
event I wanted the user to select multiplePictureBox
es. 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 anotherPictureBox
, 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 theMouseHover
event, but that will be a makeshift solution at best. EDIT: Scrap that part with theMouseHover
event, that doesn't ever fire.modified on Wednesday, May 6, 2009 5:32 AM
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
-
In the past I had trouble with a
PictureBox
es 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 ofPictureBox
es directly next to each other and with theMouseDown
event I wanted the user to select multiplePictureBox
es. 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 anotherPictureBox
, 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 theMouseHover
event, but that will be a makeshift solution at best. EDIT: Scrap that part with theMouseHover
event, that doesn't ever fire.modified on Wednesday, May 6, 2009 5:32 AM
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.
-
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
Nah,
MouseMove
fires the moment you move the mouse, so moving it around over one and the samePictureBox
firest it countless times. I realizedMouseHover
would do the same andMouseEnter
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. -
Nah,
MouseMove
fires the moment you move the mouse, so moving it around over one and the samePictureBox
firest it countless times. I realizedMouseHover
would do the same andMouseEnter
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.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