How to Display Tool Tip

This is a temporary workout. To display a tool tip, you have to manually create it. Below code will show you how is it be done.

Example 1:

public partial class Form1 : Form
{
    ToolTip tip = new ToolTip();
    public Form1()
    {
        InitializeComponent();
        ribbonButton1.MouseEnter += new MouseEventHandler(ribbonButton1_MouseEnter);
        ribbonButton2.MouseEnter += new MouseEventHandler(ribbonButton2_MouseEnter);
    }
 
    void ribbonButton2_MouseEnter(object sender, MouseEventArgs e)
    {
        tip.Show("ribbonButton2, this is.", this, e.Location.X, e.Location.Y, 1000);
    }
 
    void ribbonButton1_MouseEnter(object sender, MouseEventArgs e)
    {
        tip.Show("This is ribbonButton1", this, e.Location.X, e.Location.Y, 1000);
    }
}

Example 2:

public partial class Form1 : Form
{
    object _ob;
    Timer timer1 = new Timer();
 
    public Form1()
    {
        InitializeComponent();
        timer1.Interval = 500;
        timer1.Tick += new EventHandler(timer1_Tick);
        ribbonButton1.ToolTip = "This is ribbonButton1.";
        ribbonButton1.MouseEnter += new MouseEventHandler(ribbonButton1_MouseEnter);
        ribbonButton1.MouseLeave += new MouseEventHandler(ribbonButton1_MouseLeave);
    }
 
    void ribbonButton1_MouseLeave(object sender, MouseEventArgs e)
    {
        timer1.Stop();
    }
 
    void ribbonButton1_MouseEnter(object sender, MouseEventArgs e)
    {
        _ob = sender;
        timer1.Start();
    }
 
    void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Stop();
        if (_ob == null)
            return;
 
        int x = 40;
        int y = 100; 
 
        if (_ob.GetType() == typeof(RibbonButton))
        {
            ToolTip tp = new ToolTip();
            tp.Show(((RibbonButton)_ob).ToolTip, this, x, y, 1000);
        }
    }
}

Last edited Dec 18, 2012 at 11:09 AM by adriancs, version 2

Comments

No comments yet.