Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Implementing Dynamic ToolTips: Preventing SetToolTip stack overflow

, 17 Feb 2010
Rate this:
Please Sign up or sign in to vote.
First, why would you want to change the ToolTip text during the PopUp? Why not hook the MouseHover of the control that you want to change the ToolTip? Dynamically setting the ToolTip does not require hooking the PopUp event.How about: public partial class Form1 : Form { ...
First, why would you want to change the ToolTip text during the PopUp? Why not hook the MouseHover of the control that you want to change the ToolTip? Dynamically setting the ToolTip does not require hooking the PopUp event.
 
How about:
    public partial class Form1 : Form
    {
        Random rnd;
        ToolTip toolTip1;
        String[] tipText;
 
        public Form1()
        {
            InitializeComponent();
            InitializeToolTips();
            tipText = File.ReadAllLines(@"..\..\Form1.cs");
            rnd = new Random();
        }
 
        private void InitializeToolTips()
        {
            toolTip1 = new ToolTip();
            toolTip1.SetToolTip(button1, "Fixed text");
            toolTip1.SetToolTip(button2, "Variable text");
            button1.MouseHover += button_MouseHover;
        }
 
        private String NewTipText()
        {
            Int32 idx = rnd.Next(0, tipText.Length);
            return tipText[idx];
        }
 
        private void button_MouseHover(object sender, System.EventArgs e)
        {
            String proposed = NewTipText();
            if (!String.IsNullOrEmpty(proposed)) {
                toolTip1.SetToolTip((Control)sender, proposed);
            }
        }
    }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

William Winner
Other NOAA
United States United States
I am a commissioned officer with the NOAA Commissioned Corps.
 
Currently I am a GIS Analyst with the National Marine Fisheries Service. I have a Master's in Environmental Science and code more as a means to an end.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 17 Feb 2010
Article Copyright 2010 by William Winner
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid