1

我让超级工具提示(来自 DotNetBar)出现在 NumericUpDown 的每个控件上。但我只需要 NumericUpDown 的 TextBox 上的超级工具提示。这是我当前的代码:

foreach (Control c in NumericUpDown.Controls)
{
    NumericUpDownToolTip.SetSuperTooltip(c, NumericUpDownSuperToolTip);
}

//Declarations:
//NumericUpDownToolTip is a SuperToolTip from DotNetBar
//NumericUpDownSuperToolTip is the configuration of the SuperToolTip (for example: the text of the tooltip)

那么如何仅在文本框上设置工具提示?

4

2 回答 2

2

将您的 foreach 修改为:

foreach (Control c in NumericUpDown.Controls.OfType<TextBox>())
于 2011-09-15T19:12:18.287 回答
0

你可以用老式的方式来做:

foreach (Control c in NumericUpDown.Controls)
{
    if (!(c is TextBox)) continue;
    NumericUpDownToolTip.SetSuperTooltip(c, NumericUpDownSuperToolTip);
}

或者使用 LINQ 来完成同样的任务

var controls = NumericUpDown.Controls.Where(c => c is TextBox);

foreach (Control c in controls)
   NumericUpDownToolTip.SetSuperTooltip(c, NumericUpDownSuperToolTip);
于 2011-09-15T19:09:14.183 回答