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.
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.
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.
Open the WatchDogEditor.cs file in the Visual Studio designer and add a button control. Name it btnSetTooltip.
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)
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");
7: //Setting the Tooltip in a composite control that doesn't have a default property
8: string ValueForToolTip;
9: System.Windows.Forms.TextBox tb;
11: //Find the constituent TextBox control in the composite control's Controls collection
12: foreach (System.Windows.Forms.Control c in aaWatchdogMonitoredBitInputSource.Controls)
14: if(c is System.Windows.Forms.TextBox)
16: //Cast it to a TextBox
17: tb = (System.Windows.Forms.TextBox) c;
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));
24: //Set the Tooltip
25: m_ToolTip.SetToolTip(c, ValueForToolTip);
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)
5: string ValueForToolTip;
7: if( sender is aaTextBox)
9: ValueForToolTip = Convert.ToString(GetData(((aaTextBox) sender).Attribute));
10: m_ToolTip.SetToolTip((aaTextBox) sender, ValueForToolTip);
12: if( sender is aaTextBoxMxReference)
14: System.Windows.Forms.TextBox tb;
15: foreach (System.Windows.Forms.Control c in ((aaTextBoxMxReference) sender).Controls)
17: if(c is System.Windows.Forms.TextBox)
19: tb = (System.Windows.Forms.TextBox) c;
20: ValueForToolTip = Convert.ToString(GetData(((aaTextBoxMxReference) sender).Attribute));
21: m_ToolTip.SetToolTip(c, ValueForToolTip);
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:
And for the aaTextBoxMxReference control: