Silverlight: how to obtain the mouse wheel event and how to judge and obtain the combination key

Source: Internet
Author: User

Let's talk about how to get the scroll wheel event this time.

The mouse wheel event is not in the current version of beta2, but we can use the htmlpage object htmlpage (system. windows. browser;) (I have mentioned many times how to capture Silverlight right-click events and how to use cookies in Silverlight ).

Htmlpage. Window. attachevent ( " Dommousescroll " , Onmousewheel );
Htmlpage. Window. attachevent ( " Onmousewheel " , Onmousewheel );
Htmlpage. Document. attachevent ( " Onmousewheel " , Onmousewheel );

Private VoidOnmousewheel (ObjectSender, htmleventargs ARGs)
{

}

 

Then we will get a rotation angle attribute in the onmousewheel method.

However, the name of this attribute varies in different browsers.

From this angle, we can know that the mouse is rolling up or down.

Double Mousedelta =   0 ;
Scriptobject E = Args. eventobject;
If (E. getproperty ( " Detail " ) ! =   Null )
{ // Firefox and Apple
Mousedelta = (( Double ) E. getproperty ( " Detail " ));
}
Else   If (E. getproperty ( " Wheeldelta " ) ! =   Null )
{ // IE and opera
Mousedelta = (( Double ) E. getproperty ( " Wheeldelta " ));
}
Mousedelta = Math. Sign (mousedelta );
If (Mousedelta >   0 )
{
TXT. Text =   " Scroll up " ;
}
Else   If (Mousedelta < 0 )
{
TXT. Text =   " Scroll down " ;
}

 

Next, let's talk about how to obtain the keyboard keys (for example, we often press Ctrl + mouse or Ctrl + enter)

In fact, we only need to use an enumeration value.

Namespace System. Windows. Input
{
// Summary:
// Specifies the set of modifier keys.
[Flags]
Public   Enum Modifierkeys
{
// Summary:
// No modifiers are pressed.
None =   0 ,
//
// Summary:
// The ALT key is pressed.
ALT =   1 ,
//
// Summary:
// The ctrl key is pressed.
Control =   2 ,
//
// Summary:
// The shift key is pressed.
Shift =   4 ,
//
// Summary:
// The Windows logo key is pressed.
Windows =   8 ,
//
// Summary:
// The apple key (also known as the "Open apple key") is pressed.
Apple =   8 ,
}
}

Methods

Like registering a click event on the current page

This . Mouseleftbuttondown + =   New Mousebuttoneventhandler (page_mouseleftbuttondown );
Void Page_mouseleftbuttondown ( Object Sender, mousebuttoneventargs E)
{}

We need to perform a few operations in it to determine whether the user is still holding down a key on the keyboard.

 

Modifierkeys keys = Keyboard. modifiers;
TXT. Text =   "" ;
If (Keys & Modifierkeys. Shift) ! =   0 )
TXT. Text + =   " Shift " ;
If (Keys & Modifierkeys. alt) ! =   0 )
TXT. Text + =   " ALT " ;
If (Keys & Modifierkeys. Apple) ! =   0 )
TXT. Text + =   " Apple " ;
If (Keys & Modifierkeys. Control) ! =   0 )
TXT. Text + =   " CTRL " ;
If (Keys & Modifierkeys. Windows) ! =   0 )
TXT. Text + =   " Windows " ;
TXT. Text + =   " + Mouse clicks " ;

The above are some tips for my personal summary ~ I hope this technique will help you ^

Source code:Mouse_wheel_keys_event deom

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.