Introduction
The ToolTip control in Windows Forms is a small pop-up box that displays when you place your pointer or cursor on the control. Its purpose is to provide a brief description of the control in the Windows form. The ToolTip class is used to generate ToolTip controls and provide various types of properties, methods, events, and run-time control status.
Recommended topics, Palindrome in C#, singleton design pattern in c# and Ienumerable vs Iqueryable
ToolTip Class
In any container or control, you can utilize the ToolTip class. You may generate several tooltips for multiple controls with the aid of a single ToolTip component under the System.Windows.Forms namespace, the ToolTip class.
In C#, there are two methods for creating a ToolTip in a Windows form:
-
Design Time
It's the simplest approach to making a ToolTip, as indicated in the instructions below:
-
Create a windows form:
Visual Studio -> File -> New -> Project -> WindowsFormApp
-
Drag and drop the ToolTip from the ToolBox onto the form. When you drag and drop this ToolTip onto a form, it will immediately add it to the properties (called ToolTip on ToolTip1) of all controls in the current window.
-
After dragging and dropping, navigate to the ToolTip control's properties to customize ToolTip to your liking.
-
Run Time
It's a little more difficult than the previous way. With the help of the ToolTip class's syntax, you can construct a ToolTip control programmatically in this function.
The instructions below demonstrate how to set the generate ToolTip dynamically.
1. Create a ToolTip control using the ToolTip() constructor provided by the ToolTip class.
// Creating a ToolTip control
ToolTip t_Tip = new ToolTip();
2. After creating the ToolTip control, set the property of the ToolTip control provided by the ToolTip class.
// Setting the properties of ToolTip
t_Tip.Active = true;
t_Tip.AutoPopDelay = 4000;
t_Tip.InitialDelay = 600;
t_Tip.IsBalloon = true;
t_Tip.ToolTipIcon = ToolTipIcon.Info;
t_Tip.SetToolTip(box1, "Name should start with Capital letter");
t_Tip.SetToolTip(box2, "Password should be greater than 8 words");