An Array Of RadioButtons : RadioButtons « GUI Form « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » GUI Form » RadioButtons 
An Array Of RadioButtons
 

#include "stdafx.h"

[STAThreadAttribute]
int main(array<System::String ^> ^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<String^>^ rbText = gcnew array<String^> {L"Can", L"You", L"Click", L"More", L"Than", L"One"};
            radios = gcnew array<RadioButton^>(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(9010+(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(9010+(40*radios->Length))
            Controls->Add(label);
    }

  private:
        array<RadioButton^>^ radios; 
        Label       ^label; 

    System::ComponentModel::Container ^components;


    void InitializeComponent(void)
    {
            this->SuspendLayout();

            this->AutoScaleDimensions = System::Drawing::SizeF(613);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292273);

            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; 
        }
  };

   
  
Related examples in the same category
1.Grouping Radios
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.