Home > Net >  In c #, how to focus on listening to the operation of the mouse wheel when you are not in the form
In c #, how to focus on listening to the operation of the mouse wheel when you are not in the form

Time:10-02

I now have a form1, for example, there is a label, now I hope that any time (including the focus is not in the form1) when I scroll the mouse wheel, Numbers are written in the label + 1, could you tell me how to write, this particular hook seems to need? Trouble you greatly

CodePudding user response:

Is actually achieve chrome similar functionality bai - focus, roller can still control page scrolling
To tell the truth in addition to using hooks and handle relevant things, I also don't know other way of thinking, to learn

CodePudding user response:

As if had been achieved most of the applications are now focus page scrolling functionality to control roller oh
Don't know what is with the baby

CodePudding user response:

reference 1st floor Seilboy response:
is bai - focus, chrome similar functions page scroll wheel can still control


Focus is not in the window, roller rolling window page can still roll?

How do I have never seen such chrome?

CodePudding user response:

reference sp1234 reply: 3/f
Quote: refer to 1st floor Seilboy response:

Is actually achieve chrome similar functionality bai - focus, roller can still control page scrolling


Focus is not in the window, roller rolling window page can still roll?

How do I have never seen such chrome?

Don't listen to you say so because of the operating system, I am using win10 now as most of the software function of the QQ chat window, notepad + +

CodePudding user response:

reference 1st floor Seilboy response:
is bai - chrome similar functions focus is absent, roller can still control page scrolling
To tell the truth in addition to using hooks and handle relevant things, I don't know other thoughts, learn


If with hooks should be how to write, I realized the hooks in the mouse movement monitoring, but the mouse scroll is not

CodePudding user response:

Don't focus events, use the mousemove event
As long as the mouse on the form, the scroll wheel is + 1

CodePudding user response:

refer to the second floor token can't be empty response:
had been achieved as most applications are now focus page scrolling functionality to control roller oh
Don't know what is with the baby
Windows began to bring their own functions, 10 in the set

CodePudding user response:

Focus is not, but the mouse moved to the area of mobile
Or, at the front desk to see world, the mouse moved to the background of the browser, avoid, roller directly, the browser content slide up and down

CodePudding user response:

Reference
how to focus on listening to the operation of the mouse wheel when you are not in the form?


This is your problem with your logic,

Label don't lable, browsers don't browser, display not logic, not your problem

So: what on earth are you talking about??
1. Nuget install Gma. System. MouseKeyHook (I don't want to struggle to discuss what the hooks, the programmer should focus on the logic, hard to avoid falling into the debate on low-level boring technology, if he wanted to study how the hooks, where his source, their research)
2. The code
 public partial class Form2: Form, INotifyPropertyChanged 
{
Private string _mytext;
Private int _myvalue;

Public Form2 ()
{
InitializeComponent ();
}

Public int myvalue
{
The get=& gt; _myvalue;
Set
{
If (value=https://bbs.csdn.net/topics/=_myvalue) return;
_myvalue=https://bbs.csdn.net/topics/value;
OnPropertyChanged ();
}
}

Private void Form2_Load (object sender, EventArgs e)
{
Var hook=hook. GlobalEvents ();
Hook. The MouseWheel +=Hook_MouseWheel;

Enclosing label1. DataBindings. Add (nameof (label1. Text), and this, nameof (enclosing myvalue));

}

Private void Hook_MouseWheel (object sender, MouseEventArgs e)
{
If (e.D elta & gt; 0)
{
This. Myvalue++;
}
The else
{
Myvalue -;
}
}

The public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
Protected virtual void OnPropertyChanged ([CallerMemberName] string propertyName=null)
{
PropertyChanged? Invoke (this, new PropertyChangedEventArgs (propertyName));
}
}

CodePudding user response:

Coke is not focus it doesn't matter, as long as the mouse coordinates in form, is ok

CodePudding user response:

This feature should be provided by the Windows.
Such as win10 mouse Settings have this functionality, and should be opened by default.
Windows 7? To persuade the change win10 bai.

CodePudding user response:

Agree with 9 f method, I also recorded a video at https://www.bilibili.com/video/BV1i54y1k7Jc
  •  Tags:  
  • C#