How to set the initial delay of the ToolTip in C#?
Last Updated :
19 Jul, 2019
In Windows Forms, the ToolTip represents a tiny pop-up box which appears when you place your pointer or cursor on the control and the purpose of this control is it provides a brief description about the control present in the windows form. In ToolTip, you are allowed to set the time passes before the ToolTip box pop-up by using InitialDelay Property.
With the help of this property, you can increase or decrease the time taken by the ToolTip box before it appears on the control. The maximum limit of this property is 32767. You can set this property in two different ways:
1. Design-Time: It is the easiest way to set the value of the InitialDelay property as shown in the following steps:
2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the InitialDelay property of ToolTip programmatically with the help of given syntax:
public int InitialDelay { get; set; }
Here, the value of this property is of System.Int32 type and the period of the time is always in milliseconds.
Note: Always set the value of InitialDelay property small because if you set the larger value, then it will take more time to display on the screen. Due to large delay time the user does not enjoy the benefit of the ToolTip window.
The following steps show how to set the InitialDelay property of the ToolTip dynamically:
- Step 1: Create a ToolTip using the ToolTip() constructor is provided by the ToolTip class.
// Creating a ToolTip
ToolTip t = new ToolTip();
- Step 2: After creating Tooltip, set the InitialDelay property of the Tooltip provided by the ToolTip class.
// Setting the InitialDelay property
t.InitialDelay = 600;
- Step 3: And last add this ToolTip to the controls using SetToolTip() method. This method contains the control name and the text which you want to display in the ToolTip box.
t.SetToolTip(box1, "Name should be start with Capital letters");
Example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp33 {
public partial class Form1 : Form {
public Form1()
{
InitializeComponent();
}
private void Form1_Load( object sender, EventArgs e)
{
Label l1 = new Label();
l1.Location = new Point(140, 122);
l1.Text = "Name" ;
this .Controls.Add(l1);
TextBox box1 = new TextBox();
box1.Location = new Point(248, 119);
box1.BorderStyle = BorderStyle.FixedSingle;
this .Controls.Add(box1);
Label l2 = new Label();
l2.Location = new Point(140, 152);
l2.Text = "Password" ;
this .Controls.Add(l2);
TextBox box2 = new TextBox();
box2.Location = new Point(248, 145);
box2.BorderStyle = BorderStyle.FixedSingle;
this .Controls.Add(box2);
ToolTip t = new ToolTip();
t.Active = true ;
t.AutoPopDelay = 4000;
t.InitialDelay = 600;
t.SetToolTip(box1, "Name should be start with Capital letters" );
t.SetToolTip(box2, "Password should be greater than 8 words" );
}
}
}
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...