Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Tooltips with a NumericEditArray (Expanded)

David Goldberg posted an example on how to use tooltips with NumericEditArray controls which really helped me out. I posted a complete example method based on his code and he asked me to post it here.

--


David Goldberg's original Post :<div>Hi Adam,</div><div> </div><div>Yes, you can set tooltips for each item in a <strong>NumericEditArray</strong>.  The following instructions assume you are using C#.</div><div> </div><ol><li>Drag a ToolTip from <strong>Common Controls</strong> onto the form with the <strong>NumericEditArray</strong>.</li><li>Add the following code to your Form, after InitializeComponent()</li></ol><blockquote><blockquote>int i = 0;foreach (Control c in numericEditArray1){toolTip1.SetToolTip(c, "hello " + i.ToString());i++;}</blockquote></blockquote><div>--


</div>It wasn't clear to me whichconstructor I needed to use to create toolTip1 in this example.  I gotit working and decided to post my code.  This is a complete listing ofa method that loads a NumericEditArray control called adcValues with 10values and the assigns the tool tips.  The empty ToolTip constructor works fine.  Maybe it's obvious but I thought I would post this anyway.  private void button1_Click(object sender, EventArgs e)        {            int i = 0;            int num_adcs = 10;            double adcChannels = new doublenum_adcs;            // Fill up an array with some generic values            for (i = 0; i &lt; num_adcs; i++)            {                adcChannelsi = i * 500;            }            //            // -- START OF OPTIONAL SECTION.            //             // Just trying to format the NumericEditArray controls so that I don't need scroll bars to            // see all the values.  I fixed the max at 20 just because it seemed like a good value at             // the time.  Must have been as big as I wanted to make the dialog the control was in or             // something.Pretty clumsy but it seems to work all right            //            // Make table long enough to not need scroll bars            adcValues.Height = adcValues.ItemTemplate.Height * (num_adcs + 1);            // Add more controls if needed            if ((num_adcs &gt; 1) &amp;&amp; (num_adcs &lt; 20))            {                adcValues.ScaleMode = ControlArrayScaleMode.CreateFixedMode(num_adcs);            }            else if (num_adcs &lt; 1)            {                adcValues.ScaleMode = ControlArrayScaleMode.CreateFixedMode(1);            }            else            {               MessageBox.Show(string.Format("Problem with adcValues.  Can onlydisplay 1-20.  Only updating up to 20.  Sent = {0}", num_adcs));                return;            }            // -- END OF OPTIONAL SECTION            // Assign the array to the NumericEditArray control. It will grow as needed.             adcValues.SetValues(adcChannels);            // Create a ToolTip object without worrying about assigning it to anything yet.            ToolTip toolTip1 = new ToolTip();            i = 0;            // Add the tool tips now to each value in the NumericEditArray control.            foreach (Control c in adcValues)            {                toolTip1.SetToolTip(c, "hello " + i.ToString());                i++;            }        }

Contributors