TreeNode[] mynode = new TreeNode[5];
for (int i = 0; i<=5-1; i++)
{
   mynode[i] = new TreeNode();
   mynode[i].Text = i.ToString();
}
treeView1.Nodes.Add(mynode);

解决方案 »

  1.   

    private void AddButtons()
    {
    Button buttons=new Button[10];
    for(int i=0;i<buttons.Count;i++)
    {
     buttons[i]=new Button();
     this.Controls.Add(buttons[i]);
     buttons[i].Click=Click += new System.EventHandler(this.buttons_Click)
    }
    }private void buttons_Click(object sender, System.EventArgs e)
    {
    //....
    }
      

  2.   

    谢谢 qqq123 这位朋友!!!!!
      

  3.   

    qqq123:帮忙看一看,为什么按照所说的做会出现这种情况呢?1.  D:\MyWork\C#\ZHBL3\ZHBL3\FrmTest.cs(85): 无法将类型“System.Windows.Forms.Button[]”隐式转换为“System.Windows.Forms.Button”
    2.  D:\MyWork\C#\ZHBL3\ZHBL3\FrmTest.cs(86): “System.Windows.Forms.Button”并不包含对“Count”的定义
    3.  D:\MyWork\C#\ZHBL3\ZHBL3\FrmTest.cs(88): 无法将带 [] 的索引应用于“System.Windows.Forms.Button”类型的表达式我是初学者,能不能在详细些呢?以前用VB,现在准备转过来,谢谢了。
      

  4.   

    private void AddButtons()
    {
    Button[] buttons=new Button[10];
    for(int i=0;i<buttons.Length;i++)
    {
    buttons[i]=new Button();
    this.Controls.Add(buttons[i]);
    buttons[i].Click += new System.EventHandler(this.buttons_Click);
    }
    }
    private void buttons_Click(object sender, System.EventArgs e)
    {
    //....
    }
      

  5.   


    class YourForm : Form
    {
       private System.Windows.Forms.TextBox[] textboxes;....
    int n = 10;
    int nLeft = 10;
    int nTop = 10;
    int nHeight = 30;
    textboxes = new TextBox[n];
    for (int i=0; i < n; i++)
    {
    textboxes[i] = new TextBox();
    textboxes[i].Name = "txt" + i.ToString();
    textboxes[i].Location = new System.Drawing.Point(nLeft, i*nHeight + nTop);
    this.Controls.Add(textboxes[i]);
    }
      

  6.   

    C#中动态创建控件及事件处理程序
    http://www.programfan.com/showarticle.asp?id=2073看看这个吧
      

  7.   

    http://expert.csdn.net/Expert/topic/2206/2206319.xml?temp=.2307855