How to change the tooltip of a 3rd party composite .NET control like the ArchestrA Object Editor

by Klaus Graefensteiner 11/9/2007 6:16:28 AM

    This article is for users of the ArchestrA Object Toolkit. This post might be also useful to readers that try to change a tooltip of a composite control that is provided by any other 3rd party library. The code samples refer to the Watchdog Object that ships with the Toolkit. The Watchdog Visual Studio solution has one C# project dedicated to the editor control of the ArchestrA Object. The controls used in the composite editor control are mostly sub classes of controls found in the System.Windows.Forms namespace. By default the tooltip of each control shows the name of the ArchestrA attribute.

    clip_image001

    For most users this doesn't seem the best use of the tooltip. Especially for controls that display strings like a Textbox it would be nice if these controls would display the whole string value in the tooltip instead of the name of the data binding source.

    clip_image002

    This article describes how to code this feature in case of a library control that is a sub class of a .NET control e.g. the aaTextBox control and a composite control like the aaTextBoxMxReference control . In the basic example the tooltip will be set by a button that I added to the editor control. In a second more realistic example the change of the tooltip will be wired to the ArchestrA DataChanged events of the constituent controls.

    Basic approach:

    Open the WatchDogEditor.cs file in the Visual Studio designer and add a button control. Name it btnSetTooltip.

    clip_image003

    Double click the button. This will create and open the click handler method. Add the following lines of code:

     1:  private void btnSetTooltip_Click(object sender, System.EventArgs e)
     2:  {
     3:    //Set the Tooltip for a control that is derived from a .NET TextBox control
     4:    //This will set the value of the default property
     5:     m_ToolTip.SetToolTip(aaTimeout_Limit, "Easy Test");
     6:  
     7:    //Setting the Tooltip in a composite control that doesn't have a default property
     8:    string ValueForToolTip;
     9:    System.Windows.Forms.TextBox tb;
     10:  
     11:    //Find the constituent TextBox control in the composite control's Controls collection
     12:    foreach (System.Windows.Forms.Control c in aaWatchdogMonitoredBitInputSource.Controls)
     13:    {
     14:      if(c is System.Windows.Forms.TextBox)
     15:      {
     16:        //Cast it to a TextBox
     17:        tb = (System.Windows.Forms.TextBox) c;
     18:  
     19:        //Get the attribute value displayed in the constituent control using the Editor
     20:        //Framework's GetData() function and the control's property that represents
     21:        //the ArchestrA attribute.
     22:        ValueForToolTip = Convert.ToString(GetData(aaWatchdogMonitoredBitInputSource.Attribute));
     23:  
     24:        //Set the Tooltip
     25:        m_ToolTip.SetToolTip(c, ValueForToolTip);
     26:  
     27:      }
     28:    }
     29:  }

    More realistic implementation:

    The tooltip needs to be changed automatically after the editor opens and every time the value in the text control changes. The best approach is to trigger this change using the DataChanged event.

    The first step here is to create a method that will be called for each control event on the editor.

     1:  //Create a function that handles the ArchestrA DataChanged events of the aaTextBox and the
     2:  //aaTextBoxReference control
     3:  private void SetTooltip_Handler(object sender, ArchestraEditorFramework.DataChangeEventArgs e)
     4:  {
     5:    string ValueForToolTip;
     6:  
     7:    if( sender is aaTextBox)
     8:    {
     9:      ValueForToolTip = Convert.ToString(GetData(((aaTextBox) sender).Attribute));
     10:     m_ToolTip.SetToolTip((aaTextBox) sender, ValueForToolTip);
     11:   }
     12:   if( sender is aaTextBoxMxReference)
     13:   {
     14:     System.Windows.Forms.TextBox tb;
     15:     foreach (System.Windows.Forms.Control c in ((aaTextBoxMxReference) sender).Controls)
     16:     {
     17:       if(c is System.Windows.Forms.TextBox)
     18:       {
     19:         tb = (System.Windows.Forms.TextBox) c;
     20:         ValueForToolTip = Convert.ToString(GetData(((aaTextBoxMxReference) sender).Attribute));
     21:         m_ToolTip.SetToolTip(c, ValueForToolTip);
     22:       }
     23:     }
     24:   }
     25: }

    Then wire the events in the Visual Studio designer of each of the controls that needs to get the new tooltip to the SetTooltip_Handler method.

    For the aaTextBox:

    clip_image004

    And for the aaTextBoxMxReference control:

    clip_image005

    kick it on DotNetKicks.com

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

ArchestrA Object Toolkit | Toolkits | Wonderware

Related posts

Comments

11/9/2007 6:23:03 AM

trackback

Trackback from DotNetKicks.com

How to change the tooltip of a 3rd party composite .NET control like t

DotNetKicks.com

Comments are closed

Powered by BlogEngine.NET 1.3.0.0
Vanilla Theme by Klaus Graefensteiner

About Klaus Graefensteiner

GRAVATAR icon of Klaus Graefensteiner I enjoy the programming of machines.

E-mail me Send mail
Blogroll as OPML OPML LinkedIn Profile View Klaus Graefensteiner's LinkedIn profile

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009

Sign in