C # winform: Use the scroll wheel to control the image size and obtain the scroll wheel and mousewheel events in the middle mouse.

Source: Internet
Author: User
First, add this sentence to the form constructor.
C # Code
    1. This. Mousewheel + =NewSystem. Windows. Forms. mouseeventhandler (This. Panelappsmousewheel );
 
This. mousewheel + = new system. Windows. Forms. mouseeventhandler (this. panel?mousewheel );
C # code
  1. # Loading when region enters the form
  2. PublicFormalarminfoquery ()
  3. {
  4. Initializecomponent ();
  5. Picturebox1.imagelocation ="F: \ 1.jpg";
  6. This. Mousewheel + =NewSystem. Windows. Forms. mouseeventhandler (This. Panelappsmousewheel );
  7. // Determine whether a mouse with a scroll wheel is installed
  8. // Systeminformation. mousewheelpresent. tostring ();
  9. // Obtain the number of rows of the scroll wheel.
  10. // Systeminformation. mousewheelscrolllines. tostring ();
  11. // Determine whether the operating system supports scroll mouse
  12. // Systeminformation. nativemousewheelsupport. tostring ();
  13. # Endregion
 
# When region enters the form, it loads public formalarminfoquery () {initializecomponent (); picturebox1.imagelocation = "F: \ 1.jpg"; this. mousewheel + = new system. windows. forms. mouseeventhandler (this. panelappsmousewheel); // determines whether a mouse with a scroll wheel is installed. // systeminformation. mousewheelpresent. tostring (); // obtain the number of rows obtained when the scroll wheel is scroll. // systeminformation. mousewheelscrolllines. tostring (); // determines whether the operating system supports scroll wheel and mouse. // systeminformation. nativemousewheelsupport. tostring () ;}# endregion

Then write a mouse event Method

C # code
  1. Private VoidPanelappsmousewheel (ObjectSender, system. Windows. Forms. mouseeventargs E)
  2. {
  3. MessageBox. Show ("Rolling event captured");
  4. System. Drawing. Size T = picturebox1.size;
  5. T. Width + = E. Delta;
  6. T. height + = E. Delta;
  7. Picturebox1.width = T. width;
  8. Picturebox1.height = T. height;
  9. }
 
Private void panelappsmousewheel (Object sender, system. windows. forms. mouseeventargs e) {MessageBox. show ("rolling event captured"); system. drawing. size T = picturebox1.size; T. width + = E. delta; T. height + = E. delta; picturebox1.width = T. width; picturebox1.height = T. height ;}

If the "rolling event captured" is output, the scroll wheel event is captured successfully, and you can write the event to be handled by the scroll wheel.

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.