首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# Change NumericUpDown.Increment Foreach NumericUpDown C#C# GroupBox (儿童)

C# Change NumericUpDown.Increment Foreach NumericUpDown C#C# GroupBox (儿童)
EN

Stack Overflow用户
提问于 2018-04-07 17:13:04
回答 1查看 217关注 0票数 0

我有一个名为“NumericUpDown”的NumericIncrementPrecision控件,当我更改这个NumericUpDown的值时,几乎所有的NumericUpDown框都会更改增量:

代码语言:javascript
复制
NumericTriggerLocationX.Increment = (decimal)NumericIncrementPrecision.Value;
NumericTriggerLocationY.Increment = (decimal)NumericIncrementPrecision.Value;
[...]
NumericObjectLocationYaw.Increment = (decimal)NumericIncrementPrecision.Value;

但是我有100+ NumericUpDown控件,在GroupBox中,在TabPage中,在表单中,等等。我已经尝试过了,但是没有发生任何事情:

代码语言:javascript
复制
foreach (Control c in TabEditor.Controls)
{
    foreach (Control childc in c.Controls)
    {
        if (childc is NumericUpDown)
        {
            NumericUpDown test = (NumericUpDown)childc;
            test.Increment = (decimal)NumericIncrementPrecision.Value;
        }
    }
}

有什么想法吗?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-07 17:49:09

我们需要做得更深入:

代码语言:javascript
复制
foreach (Control c in TabEditor.Controls)
{
    // c will be a TabPage
    foreach (Control childc in c.Controls)
    {
        // childc is a control inside TabPage, e.g GroupBox
        foreach (NumericUpDown nud in childc.Controls.OfType<NumericUpDown>())
        {
            nud.Increment = (decimal)NumericIncrementPrecision.Value;
        }
    }
}

如果所有NumericUpDowns都在一个GroupBox中,那么只检查该GroupBox:

代码语言:javascript
复制
foreach (NumericUpDown nud in singleGroupBox.Controls.OfType<NumericUpDown>())
{
    nud.Increment = (decimal)NumericIncrementPrecision.Value;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49709895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档