仅在1个NumericUpDown控件上执行操作

时间:2011-09-15 19:07:07

标签: c# controls tooltip numericupdown

我让一个supertooltip(来自DotNetBar)出现在NumericUpDown的每个控件上。但我只需要NumericUpDown的TextBox上的supertooltip。这是我目前的代码:

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)

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

2 个答案:

答案 0 :(得分:2)

将你的foreach修改为:

foreach (Control c in NumericUpDown.Controls.OfType<TextBox>())

答案 1 :(得分: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);
相关问题