Big Bug Ban

兴趣 践行 创新

c++ .net 动态添加控件 及其事件处理

 

一个简单的例子

例子如下

Capture

按下button后实时生成了个RadioButton

然后再单击生成的RadioButton

字由A变成DDD

	System::Windows::Forms::RadioButton^ node1 = gcnew System::Windows::Forms::RadioButton();
	node1->AutoSize = true;
	node1->Location = System::Drawing::Point(19, 34);
	node1->Name = L"node1";
	node1->Size = System::Drawing::Size(32, 17);
	node1->TabIndex = 0;
	node1->TabStop = true;
	node1->Text = a;
	node1->UseVisualStyleBackColor = true;
	node1->Click += gcnew System::EventHandler(this, &Form1::node_Click);
	this->Controls->Add(node1);

button1_Click里面写上这个

注意最后的node1->Click += gcnew System::EventHandler(this, &Form1::node_Click);

就是事件绑定,我将其绑定到了node_Click这个函数上

然后再写node_Click函数


void node_Click(System::Object^  sender, System::EventArgs^  e) {
         System::Windows::Forms::RadioButton^ a= (System::Windows::Forms::RadioButton^)sender;
	 a->Text="DDD";
 }

Written by princehaku

12月 23rd, 2009 at 1:21 下午

Posted in 未分类

Tagged with

without comments

Leave a Reply