Search:

Custom Search
_________________________________________________________________

Wednesday, May 7, 2008

Creating Tooltip to Button Control from scratch

First of all, start by creating a new Windows form application in Visual Studio 2005. (You can download the Express Edition clicking the link on My Links section).

After that, place a Button Control somewhere in the form as you see below:

Ok, now we can proceed to add the tooltip event to the button1. This is actually very easy. I will show you the way I use for doing this.

Navigate through the toolbox until you find the tooltip control. Grab the control and place it somewhere in the form.

You will see that the Control is placed in a bar below the form. Also the Tooltip Control is created with the name tooltip1. Ok, now let’s add some event and write a few code lines.

Click the button1 and under properties double click the MouseHover event. This creates the method that we use for the tooltip control. Now in the method body add this line of code:

toolTip1.SetToolTip(button1, "Information for Button1");

Great, now run the app and see what happens. It should look something like this:


Some other cool features on this C# Control:
-
toolTip1.IsBalloon = true;
(Converts to a ballon window)



- toolTip1.ToolTipIcon = ToolTipIcon.Error;
(Assign icon to the tooltip)

- toolTip1.ToolTipTitle = "This is the Title";
(Assigns a title)

Complete Code:

private void button1_MouseHover(object sender, EventArgs e)
{
toolTip1.SetToolTip(button1, "Information for Button1");
toolTip1.IsBalloon = true;
toolTip1.ToolTipIcon = ToolTipIcon.Error;
toolTip1.ToolTipTitle = "This is the Title";
}

No comments: