Let usercontrol process the arrow key

Source: Internet
Author: User

I wroteUsercontrol,Need to handleArrow keys. (Up, down, left, right ).However, these four keys belongDialogkeyThere are two solutions to makeUsercontrolInOnkeydownTo process these four keys.

Solution 1:

Heavy LoadProcessdialogkey.

Protected Override BoolProcessdialogkey (KeysKeydata)

{

If(Keydata =Keys. Up | keydata =Keys. Down

| Keydata =Keys. Left | keydata =Keys. Right)

Return False;

Else

Return Base. Processdialogkey (keydata );

}

 

Solution 2:

Heavy LoadProcesskeypreview, MandatoryAddKeyMessage event distribution logic; then reloadIsinputkey.

Protected Override BoolProcesskeypreview (RefMessage m)

{

If(Base. Processkeyeventargs (RefM ))

{

Return True;

}

Return Base. Processkeypreview (RefM );

 }

Protected Override BoolIsinputkey (Keys keydata)

{

If(This. Focused)

{

Keys keys1 = (keydata & keys. keycode );

Switch(Keys1)

{

CaseKeys. Up:

CaseKeys. down:

CaseKeys. left:

CaseKeys. Right:

{

Return True;

}

}

}

Return Base. Isinputkey (keydata );

}

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.