# Tuesday, September 22, 2009
« New projects take time | Main | Tip of the day: More WinForm tooltip tip... »

You can always grab the ToolTip control out of the toolbox, but I prefer to add a common function to a base form so I don't have to remember to add this control to the form. Then, any time I want to add a tooltip, I pass in the control and the text, and this simple snippet will take care of it for me. I remembered it as I needed to add some tooltips, which is something the existing application lacks.

        protected void SetToolTip(IContainer component, Control ctrl, string tip)

        {

            try

            {

 

                ToolTip tooltip = new ToolTip(component);

                tooltip.SetToolTip(ctrl, tip);

                tooltip.Active = true;

            }

            catch

            {

                //Don't worry

            }

        }

 

Usage:

   41 SetToolTip(this.components, lvwCategories, "Right click for menu options...");