MouseWheel Question

J

Jordi Rico

Hi all,

I'm trying to do something and I don't know if it's already
implemented or I have to do a heavy workaround for this.
The fact is, I need to capture MouseWheel (something quite simple),
but I need to capture not every event, but the last event triggered.
I explain, it's an application which must make some calculations over
an image when user zooms over it (with mouse wheel). The problem is
that if an user makes a long movement with mouse wheel, it will
trigger for example 5 times, giving a delta value for each of 120,
when I only want the total value of 600 to make only one calculation,
and thus optimize everything.
Can I get the total value when user has finised moving the wheel?

Thanks for everything.
 
N

not_a_commie

I'm not aware of any way to do what you're asking. I think you do have
a few options, though. First, are you resizing with the
Graphics.Transform or are you actually resizing the image through some
other algorithm? Regardless, if you use NearestNeighbor for either one
it should happen quickly enough. Then after it's been stable for a
second you can run another resize pass with a better-looking
algorithm. If you put your resize into another thread you can abort
that thread when another event comes in.

A better option, though, would be to use WPF. If you use WPF
transforms the image resize will happen in hardware. This will be fast
enough to keep up with the mouse wheel. In addition, you can capture
the PreviewMouseWheel event, determine if the cursor is over your
window (IsMouseOver), and then handle the event (e.Handled = true).
That way you don't even need focus on your window to make the mouse
wheel zoom work correctly.
 
M

Martin

Hi,

what commie wrote sounds ok.
In my opinion you should use a timer and a thread to do this.
However you should not abort your thread every time a new event comes in.
That is more costly than one should think. And you'd cause numerous
ThreadAbortExceptions, that you might not want to have (slowdown).
Instead use Thread.Sleep(minimumUpdateLag) where updateInterval is the
minimum time lag you want to have for your update.
The easiest approach from that direction would be to store the time of the
last
mouse wheel event and the increment value in a list.
Now, say you have entered your OnMouseWheel(...) for the fifth time and
store the last values in your list, your thread wakes up and looks at the
topmost time value.
If the time span is is bigger than your desired delay, you make your
updates. If not, you put your thread to sleep angain. and so on... tinker
with variables delay and minimumUpdateLag to fine tune your overall update
delay.
I think, that should work ;)

good luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top