簡體   English   中英

C#更改NumericUpDown.Increment Foreach NumericUpDown在GroupBox內部在其他GroupBox內部(子級)

[英]C# Change NumericUpDown.Increment Foreach NumericUpDown Inside GroupBox Inside Other GroupBox (Children)

我有一個名為“ NumericIncrementPrecision”的NumericUpDown控件,當我更改此NumericUpDown的值時,幾乎所有NumericUpDown框的增量都會更改:

NumericTriggerLocationX.Increment = (decimal)NumericIncrementPrecision.Value;
NumericTriggerLocationY.Increment = (decimal)NumericIncrementPrecision.Value;
[...]
NumericObjectLocationYaw.Increment = (decimal)NumericIncrementPrecision.Value;

但是我在Form等的TabPage里面的GroupBox里面有100+個NumericUpDown控件。我已經嘗試過了,但是沒有任何反應:

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;
        }
    }
}

任何想法?

謝謝。

我們需要更深入:

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:

foreach (NumericUpDown nud in singleGroupBox.Controls.OfType<NumericUpDown>())
{
    nud.Increment = (decimal)NumericIncrementPrecision.Value;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM