1、button event:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Button^ thisBox = safe_cast<Button^>(sender);
textBox2->Text = thisBox->Text;
}
2、radioButton:
比較高級的寫法
private: System::Void radioButton4_CheckedChanged( System::Object^ sender, System::EventArgs^ e) {
array<RadioButton ^, 2>^buttons = { { radioButton4, radioButton5, radioButton6 },{ radioButton7, radioButton8, radioButton9 } };
int i;
for (i = 0; i < 3; i++) {
if (buttons[0,i]->Checked) textBox3->Text = "Group1OK" + i.ToString();
}
for (i = 0; i < 3; i++) {
if (buttons[1, i]->Checked) textBox2->Text = "Group2OK" + i.ToString();
}
}
更高級的寫法
private: System::Void radioButton4_CheckedChanged( System::Object^ sender, System::EventArgs^ e) {
array<RadioButton ^, 2>^buttons = { { radioButton4, radioButton5, radioButton6 },{ radioButton7, radioButton8, radioButton9 } };
array<TextBox ^>^textboxs = { textBox3, textBox2 };
int i,j;
for (j = 0; j < 2; j++) {
for (i = 0; i < 3; i++) {
if (buttons[j,i]->Checked) textboxs[j]->Text = "Group" + j.ToString() + "OK" +i.ToString();
}
}
}
沒有留言:
張貼留言