#include "stdafx.h"
[STAThreadAttribute]
int main(array ^args)
{
Application::Run(gcnew Form1());
return 0;
}
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
array^ rbText = gcnew array {L"Can", L"You", L"Click", L"More", L"Than", L"One"};
radios = gcnew array(6);
label = gcnew Label();
for (int i = 0; i < radios->Length; i++)
{
int j = 50*i;
radios[i] = gcnew RadioButton();
radios[i]->BackColor = Color::FromArgb(255,j+5,j+5,j+5);
radios[i]->ForeColor = Color::FromArgb(255,250-j,250-j,250-j);
radios[i]->Location = Drawing::Point(90, 10+(40*i));
radios[i]->TabIndex = i;
radios[i]->TabStop = true;
radios[i]->Text = rbText[i];
radios[i]->CheckedChanged +=
gcnew EventHandler(this, &Form1::radioCheckedChanged);
}
Controls->AddRange(radios);
label->Location = Drawing::Point(90, 10+(40*radios->Length));
Controls->Add(label);
}
private:
array^ radios;
Label ^label;
System::ComponentModel::Container ^components;
void InitializeComponent(void)
{
this->SuspendLayout();
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 273);
this->Text = L"An Array Of Radios";
this->ResumeLayout(false);
}
private:
void radioCheckedChanged(Object ^sender, EventArgs ^e)
{
RadioButton ^rb = (RadioButton^)sender;
if (rb->Checked == true)
label->Text = rb->Text;
}
};