How to create ToolTip for a Windows Form Control using Visual C# (in .NET Framework)

Sometimes, we may want to display important help text to the user when he or she hovers over a control. For example, you may have a label in your application and you want that the user should know upon hovering what the label text signifies. This is when ToolTip comes into picture. Tooltip is basically a small “hover box” in which the information about the item being hovered upon is displayed. Here, we will learn how to add ToolTip to a windows form control (consisting of labels and textboxes) using C# (in .NET framework). Suppose we have a label as Salary and corresponding to it two textboxes in which some random figures are getting displayed, as shown below:

Windows form control

Now, we want that whenever a user hovers on the label and textboxes then some help text should get displayed. For example, here we are displaying salary figure of an employee. The first textbox displays salary in $ and second textbox in Rs. To create tooltip for these three controls, open the code of the form and paste the following code in it:

private void myToolTip()
        {
            ToolTip myToolTip = new ToolTip();
            myToolTip.SetToolTip(textBox1, "in $");
            myToolTip.SetToolTip(textBox2, " in Rs");
            myToolTip.SetToolTip(label1, "Per Month");
        }

Note: Make sure you have the System.Windows.Forms namespace added at the beginning of the code.

Now, in order to setup the tooltip for all these three controls we just need to call this function when this form loads. Lets add this immediately after initialization of the form components. See the complete code below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyToolTip
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "50";
            textBox2.Text = "250";
            myToolTip();

        }
        private void myToolTip()
        {
            ToolTip myToolTip = new ToolTip();
            myToolTip.SetToolTip(textBox1, "in $");
            myToolTip.SetToolTip(textBox2, " in Rs");
            myToolTip.SetToolTip(label1, "Per Month");
        }
    }
}

Save the code and run it. Now, move your cursor over the label and textboxes. You will see the tooltip is displayed, as shown below:

Window form tooltip for label

Visula Studion C# .NET Windows Form displaying tool tip

Visual Studio C# .NET displaying textbox tooltip in windows form

Explanation of the code:

Here, we have used the ToolTip class of the System.Windows.Forms namespace. This class represents a small rectangular pop-up window which is used to specifically display a control’s purpose when user hovers over it. Here, first we make an object of the ToolTip class and then using the SetToolTip function we set the information to be displayed over the control. The SetToolTip function takes in two arguments, the first is the control name and the second is the caption to be displayed.

ToolTip myToolTip = new ToolTip();
myToolTip.SetToolTip(textBox1, "in $");

Using the above code, we have passed the control name (for example textBox1), and the text to be displayed upon hovering (for example “in $”) as arguments in the SetToolTip function. Upon running the code it renders the tooltip text upon hovering.

In a similar fashion, you may add ToolTips to other windows form controls of your choice.

Tags:

Comments

Member since:
25 July 2016
Last activity:
50 weeks 4 days

in order to setup the tooltip for all these three controls we just need to call this function when this form loads. Lets add this immediately after initialization of the form components. 

https://medium.com/@adelaidebella143/custom-gable-boxes-for-your-busines...

Note:- This post has been edited by Julyeena at Fri, 2016-09-30 13:10.

Member since:
17 May 2016
Last activity:
1 year 17 weeks

a user hovers on the label and textboxes then some help text should get displayed. For example, here we are displaying salary figure of an employee.www.buylortabonline.net

Note:- This post has been edited by ameliajorden at Tue, 2016-05-17 20:42.

Member since:
1 May 2014
Last activity:
3 years 3 weeks

Tooltip is basically a small “hover box” in which the information about the item being hovered upon is displayed. http://www.pass4sureexam.co/70-467.html

Member since:
7 August 2017
Last activity:
6 weeks 1 day

kanye west shoes

michael kors bags

ua shoes

ray ban erika

prada handbags

payless shoes online

official kate spade website

coach outlet online

pandora rings

pandoracharms

pandora rings uk

Coach Sunglasses Outlet

balenciaga outlet

Engagement Rings - Official

Nike Air Max 180

official michael kors

Ray Ban sunglasses

shoes sale

Nike Air Max

Air Max 180

burberry outlet

Dreamland Jewelry - Official

birkenstock sandals

birkenstock

Nike Air Max Couple

coach outlet online

prada outlet online

louis vuitton outlet online

Nike Air Jordan

gel kayano

official michael kors

michael kors outlet bags

Hugo Boss Store

payless shoes

Premier Jewelry - Official

ray ban outlet

Coach Handbags

pandora sale

coach watches

nike store

football jerseys

louis vuitton outlet online

coach outlet online sale

Add Your Link Free

backlink

louis vuitton us

michael kors

Nike Air Jordan Enfants

michael kors

Michael Kors Handbags Outlet Sale

kate spade outlet online

Green Cleaned

ugg boots

sunglasses

Nike Blazer Femmes

evbid

Wine

coach outlet

birkenstock outlet

Burberry Australia

payless near me

Chanel Outlet

north face sale

Nike Air Max

Prada Shoes - Official

michael kors outlet

ray ban wayfarer sunglasses

Oakley Sunglasses

puma sneakers outlet

payless shoes

nike free shoes

diesel watches

burberry outlet canada

prada sale

puma sneakers sale

louis vuitton outlet

Air Max 180 Homme

Jewelry Armoire - Official

coach handbags sale

Hermes Outlet

timberland shoes

Nike Air Max 2017

coachs outlet

louis vuitton outlet online

Nike Jordans

football jerseys

burberry outlet sale

Nike Free 3.0

michael kors outlet online

ray ban wayfarer

ray ban sunglasses

Rolex Watch

michael kors

michael kors

nike huarache shoes

ray ban sale

Adamson

pandora necklaces

kate spade italy

coach australia

pandora uk

pandora uk

swatch watch

michael kors watches

michael kors

rayban prescription sunglasses

Brighton Jewelry - Official

prada outlet online

Nike Air Force

michael kors outlet

fulam shoes

softball jerseys

Nike Air Max

balenciaga us

Air Max 1 Homme

michael kors

Watches

Air Jordan Enfant

chrome store canada

sunglasses store

coach outlet

michael kors outlet

Nike Free Run

mk outlet online

michael kors outlet

the beat

seiko watches

michael kors

Lifestyle

Air Max 90 Femme

hermes outlet

Nike Air Jordan enfants

hermes outlet

prada purses

kate spade outlet

nike jordan shoes

me adc8.7