Visual Basic Tutorial: Click and Mouse Hover Event in Visual Basic

Description:

Click and Mouse Hover Event in Visual Basic- In this article, I am going to show you how to use mouse hover in Visual basic, in our example should contain on the screen a text label and a Button. The label will display the text “Programming Digest”, and when you click on the command button, having ” Click me ” caption, a dialog box will open with the message” Hello Programming Digest! ” In addition, when the mouse pointer is hovering over the text label (the same the MouseHover event), a dialog with the text “Mouse Hover Event “.


Creating MouseHover project in Visual Basic:

Start Visual Studio 12, click on the file in the File menu click on new, in the new dropdown menu click on Project, or simply press Ctrl+Shift+N. In the New Project window that opens, in the left column, find the Visual item Basic, and then in the Templates area – in the middle column – select Windows Forms Application template. Write the project name MouseHover, and click on the OK button.

visual basic mouse hover



In the form designer, from the Toolbox panel, drag a Label and a button to the form I set the label name as lblshow, and for a button I set BtnClick, and then design form to your liking in my case I designed as shown below.

visual basic mouse hover

Now let’s add three event handlers to the program code. To do this, in the Properties panel, click on the lightning bolt (Events)

visual basic mouse hover


and double-click consecutively select:

form load event Form_Load;

visual basic mouse hover

event – click on the BtnClick_Click button;

visual basic mouse hover

event lblShow_MouseHover.

visual basic mouse hover

This will switch to the tab of the program code Form1.vb, and the environment Visual Studio 12 will generate three empty event handlers. For example, the last event handler will look like this:


Between these two lines, insert a call to the dialog box:

Now let’s check the capabilities of the program – press the <F5> key, “hang” with the mouse pointer over Label1, click on the Button1 button. Everything is working!

So, back to the form load event – the control environment generated an empty handler for it:

Next, I would like to see the top left of the form on a blue background (in the so-called title bar) was not the Form1, but something meaningful. For example, the word ” Simple Mouse Hover Event”  To do this, set this string to the Text property of the form below. To do this, set this string to the Text property of the form below. Because we change the property of the Form1 object inside the form-related event handler, you must access the form either through the Me reference or using the MyBase or MyClass keywords:


Complete code of Visual basic Mouse Hover Event:

Output:

When you click on the button it will show the following output

visual basic mouse hover



And when you, hover the mouse pointer on the label it will show the following output:

visual basic mouse hover

Recommended For You

About the Author: Fawad

My name is Shahzada Fawad and I am a Programmer. Currently, I am running my own YouTube channel "Expertstech", and managing this Website. My Hobbies are * Watching Movies * Music * Photography * Travelling * gaming and so on...

Leave a Reply

%d bloggers like this: