Thursday, April 12, 2012

How to create user control groupbox object in VC++?

I am trying to extend the groupbox class to a temp_groupbox class which includes two radiobuttons inside the groupbox. I am facing two problems. First, I don't know how to set the two lines of event handler code for the radiobuttons because I think I should set them in the window form class NOT in this temp_groupbox class. Am I right? Second, I can only see a groupbox (small, not the size that I set in this class. Basically, there is something wrong) in my window form and I cannot see any radiobutton (even if I delete those two lines of even handler code.) Please help



        public ref class temp_groupbox: public GroupBox
{
public: temp_groupbox(int a, int b, String ^groupboxname){

// Create and initialize a GroupBox and two RadioButton controls.
GroupBox^ groupBox1 = gcnew GroupBox;
RadioButton^ radioButton1 = gcnew RadioButton;
RadioButton^ radioButton2 = gcnew RadioButton;

// Add the RadioButtons to the GroupBox.
groupBox1->Controls->Add( radioButton1 );
groupBox1->Controls->Add( radioButton2 );

groupBox1->Location = System::Drawing::Point(a, b);
groupBox1->Size = System::Drawing::Size(800, 800);
groupBox1->TabIndex = 0;
groupBox1->TabStop = false;

radioButton1->Name = L"radioButton1";
radioButton2->Name = L"radioButton2";


radioButton1->Size = System::Drawing::Size(85, 17);
radioButton2->Size = System::Drawing::Size(85, 17);

radioButton1->Location = System::Drawing::Point(130, 40);
radioButton2->Location = System::Drawing::Point(40, 140);

radioButton1->TabIndex = 1;
radioButton1->TabStop = true;

radioButton2->TabIndex = 2;
radioButton2->TabStop = true;

radioButton1->UseVisualStyleBackColor = true;
????radioButton1->CheckedChanged += gcnew System::EventHandler(this, radioButton1_CheckedChanged);
radioButton2->UseVisualStyleBackColor = true;
????radioButton2->CheckedChanged += gcnew System::EventHandler(this, radioButton2_CheckedChanged);
groupBox1->SuspendLayout();
groupBox1->ResumeLayout(false);
groupBox1->PerformLayout();
}



};// end ref class


The following is the way that I call the temp_groupbox class form my window form class



            temp_groupbox^ Temp1 = gcnew  temp_groupbox(120, 130, "asd");
Controls->Add(Temp1);
SuspendLayout();
ResumeLayout(false);




No comments:

Post a Comment