Page 53 - Computing Book 8
P. 53

Developing Applications – Visual Studio                                              Class 8


               Mouse Events

               Events are basically a user action like a key press, clicks, mouse movements, etc., or some
               occurrence like system generated notifications. Applications need to respond to events when they
               occur. Mouse events occur with mouse movements in forms and controls. Following are the various
               mouse events related to a Control class.
                   •  MouseDown − it occurs when a mouse button is pressed
                   •  MouseEnter − it occurs when the mouse pointer enters the control element
                   •  MouseHover − it occurs when the mouse pointer hovers over the control element
                   •  MouseLeave − it occurs when the mouse pointer leaves the control element
                   •  MouseMove − it occurs when the mouse pointer moves over the control element
                   •  MouseUp − it occurs when the mouse pointer is over the control element and the mouse
                       button is released
               Follow the steps to create a program in which we will detect the Mouse Event in VS.
                   •  The MouseHover event triggers when the mouse cursor hovers over a certain area.
                   •  In the following example, we are going to display a pop-up window containing a message,
                       whenever the mouse hovers on the button inside our program’s form.
                   •  Create a new form only with one button.
                   •  Double click on the button to open the script
                       menu and then open the general tab on the
                       top of the current script window as shown in
                       the example.
                   •  Select (Form1 Events).
                   •  Then open the declaration window right next to it to select the MouseEvent by scrolling
                       down which is MouseHover in this case
                   •  After selecting the MouseHover option from the declaration window, additional code will
                       automatically be added.
                   •  In that part, we will add a predefined feature MsgBox().
                   •  Next, we will declare a string value to display in parenthesis of this MsgBox(“this popup
                       window appears whenever the mouse hovers on this button”)









                      Add this
                      piece of
                       code


                   •  Execute the program by debugging and also test it by Hovering the mouse on the button.














               The City School /Academics/Computing Curriculum/Class 8/2020-2021                Page 52 of 75
   48   49   50   51   52   53   54   55   56   57   58