PerformanceCounter^ Pfc1 = gcnew PerformanceCounter();  // 这是 VC.NET语法,性能计数器控件 
PerformanceCounter^ Pfc2 = gcnew PerformanceCounter(); 
...... 请问怎样动态创建PerformanceCounter控件 ( 在一个循环里 )

解决方案 »

  1.   

    cs吗?以前做过c#里面的动态生成控件就是写代码TextBox newTextBox = new TextBox();
    newTextBox.Text = "";
    newTextBox.ID = "";
    newTextBox.Left = 
    位置累加bs没做过
    不过可能用js
      

  2.   

    TO楼上: 是WINDOWS 窗体应用程序
      

  3.   

    array<PerformanceCounter^>^ pw = gcnew array<PerformanceCounter^>(4);我尝试这样来申请一个控件数据,编译通过.pw[0]->CategoryName = "Process";
    但是设置属性时报错(设置其他属性也是如此),"未将对象引用设置到实例"...大概是这样..
      

  4.   

    TextBox newTextBox = new TextBox(); 
    newTextBox.Text = ""; 
    newTextBox.ID = ""; 
    newTextBox.Left = 
    位置累加 bs没做过 
    不过可能用js
      

  5.   

    array <PerformanceCounter^>^ pw = gcnew array <PerformanceCounter^>(4); 你写的本来就是正确滴
    pw[0]->CategoryName = "Process"; 
    这句实际也没错不过,你确认你p[0]对象存在,你只是申明了一个长度为4的array,但没往里面放任何数据对比下面的c#代码IList<TextBox> s = new TextBox[4];  s[0].Text = "aa";你认为这样是可以正常运行吗?很明显不能。因为他没有初值,s[0]并不存在,要知道你现在是使用一个引用对象这个与值对象不同,他本身是没有初始值滴,所以你自己要初始化他
       IList<TextBox> s = new TextBox[4];
                s[0] = new TextBox();//你只有初始化了,下面才能使用
                s[0].Text = "aa";