5 Replies - 219 Views - Last Post: 03 November 2019 - 08:06 PM Rate Topic: -----

#1 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 12:16 PM

I set the width of a Form's pictureBox with a value widthnumvalue.
Is there a way to create the following mouse wheel setup to adjust the value constantly?
This is the behaviour in question:
When moving the mouse wheel to the first possible spot in upwards direction, the value should always increase by +1 every 1ms,
stop at the max value of 400 and also stop at the current value when the mousewheel changes again to any next spot in upwards direction.
Decreasing should work in the same way using mouse wheel downwards direction(min number limit here is 1 for example).
Do you know a simple and solid way to code that?


Is This A Good Question/Topic? 0
  • +

Replies To: Winforms - Create this mouse wheel setup to adjust a numbervalue?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15359
  • View blog
  • Posts: 61,583
  • Joined: 12-June 08

Re: Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 12:48 PM

Have you peeped at the mousewheel event for your given control?

https://docs.microso...etframework-4.8
Was This Post Helpful? 0
  • +
  • -

#3 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Re: Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 04:37 PM

I started with the basic setup and defined a mousedeltaval, so that each upwards move of the mousewheel returns 1, each downwards move -1.
(int mousedeltaval = e.Delta / 120)
When I start like this, how could I continue from here?
Perhaps something like this could be done to realize the behaviour I was talking about?:
1st case upwards; How can I create and trigger a constant increase of a specific value(with widthnumvalue: set widthnumvalue to current widthnumvalue +1 every 1ms), after the mousewheel returned 1 and as long as widthnumvalue is lower than 401?
2nd case upwards; How can I effectively define a "when mousewheel returned 1 more than 1 time - if check" to manually stop the increase at the current value?
When this check was true or after doing the same with the two cases for -1(here, decrease widthnumvalue as long as greater than 0), allow starting from a 1st case(for -1 or 1) again?

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7137
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 06:18 PM

What's keeping you from keeping track of the number of times you get the mousewheel message, the total movement of wheel due to the delta, and then applying your acceleration steps to those values?
Was This Post Helpful? 0
  • +
  • -

#5 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Re: Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 07:48 PM

Well, that's why I'm here, because I'm not very familiar with these type of task.
I have a general idea, but I'm not sure how to solve my problem effectively in the code.
Since it looks like a basic task to me, I thought the chances are not too bad that someone with more experience
should be able to figure out a little code example which allow me to better understand my possible options for
the important parts of my question. What methods would you suggest to code the steps we mentioned in this topic?
Thanks for any advice.

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7137
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Winforms - Create this mouse wheel setup to adjust a numbervalue?

Posted 03 November 2019 - 08:06 PM

You would solve it the same way you would solve any other programming problem.

If you were hoping someone could just point you to a ready made API in the WinForms library to do this stepped velocity/acceleration, unfortunately there isn't one.

If you dig through older DOS era mailing lists you'll likely find similar questions regarding detecting and modulating mouse pointer or joystick movements. In present day game programming forums, you'll also likely find similar questions.

Anyway, I gave you the rough parameters of what you needed to watch: the cummulative sum of the movements, the time period over which that movement occurs.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1