Winforms 是System.Windows.Forms.Control.ControlCollection.Add幂等元吗?

Winforms 是System.Windows.Forms.Control.ControlCollection.Add幂等元吗?,winforms,Winforms,换句话说,下面代码中的第2行会有任何影响吗 // let's assume that myForm has not previously been added myControlCollection.Add(myForm); myControlCollection.Add(myForm); // line 2 不,第二行不会有任何效果。集合不会两次添加同一控件实例。否第二行不会有任何效果。集合不会两次添加同一个控件实例。第二行的执行不会有任何影响。第二行的执行不会有任何影响。我相信立即连

换句话说,下面代码中的第2行会有任何影响吗

// let's assume that myForm has not previously been added  
myControlCollection.Add(myForm);
myControlCollection.Add(myForm); // line 2 

不,第二行不会有任何效果。集合不会两次添加同一控件实例。

否第二行不会有任何效果。集合不会两次添加同一个控件实例。

第二行的执行不会有任何影响。

第二行的执行不会有任何影响。

我相信立即连续执行两次
add
不会有明显效果。但是,如果有使用其他控件的中间
Add
调用,它将-因为
Add
更新Z顺序,将新添加的控件发送到后面。例如:

using System;
using System.Drawing;
using System.Windows.Forms;

class Test
{
    static void Main()
    {
        Form f = new Form();
        Button b1 = new Button
        {
            Location = new Point(50, 50),
            Size = new Size(40, 40),
            Text = "b1"
        };
        Button b2 = new Button
        {
            Location = new Point(70, 70),
            Size = new Size(40, 40),
            Text = "b2"
        };

        f.Controls.Add(b1);
        f.Controls.Add(b2);
//        f.Controls.Add(b1); 
        Application.Run(f);
    }
}

这将在
b2
前面显示
b1
,但是如果您取消对
Add(b1)
的第二个调用的注释,顺序将颠倒。

我相信立即连续执行两次
Add
不会有明显的效果。但是,如果有使用其他控件的中间
Add
调用,它将-因为
Add
更新Z顺序,将新添加的控件发送到后面。例如:

using System;
using System.Drawing;
using System.Windows.Forms;

class Test
{
    static void Main()
    {
        Form f = new Form();
        Button b1 = new Button
        {
            Location = new Point(50, 50),
            Size = new Size(40, 40),
            Text = "b1"
        };
        Button b2 = new Button
        {
            Location = new Point(70, 70),
            Size = new Size(40, 40),
            Text = "b2"
        };

        f.Controls.Add(b1);
        f.Controls.Add(b2);
//        f.Controls.Add(b1); 
        Application.Run(f);
    }
}
这将在
b2
前面显示
b1
——但如果取消对
Add(b1)
的第二次调用的注释,则顺序将颠倒