#pragma once
namespace Q1092727 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TableLayoutPanel^ tableLayoutPanel1;
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// tableLayoutPanel1
//
this->tableLayoutPanel1->ColumnCount = 2;
this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
50)));
this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent,
50)));
this->tableLayoutPanel1->Location = System::Drawing::Point(63, 30);
this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
this->tableLayoutPanel1->RowCount = 2;
this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 50)));
this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 50)));
this->tableLayoutPanel1->Size = System::Drawing::Size(386, 264);
this->tableLayoutPanel1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(498, 361);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(88, 25);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(609, 409);
this->Controls->Add(this->button1);
this->Controls->Add(this->tableLayoutPanel1);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
add(2,2);
}
System::Void add(int Col_Num, int Row_Num){
int indexNum = 0;
for ( int i = 0; i < Col_Num; i++ )
{
for ( int j = 0; j < Row_Num; j++ )
{
Panel^ pn = gcnew Panel();
CheckBox ^cb = gcnew CheckBox();
cb->Size = System::Drawing::Size(50, 25);
Label^ lb = gcnew Label();
pn->Controls->Add(cb);
pn->Controls->Add(lb);
lb->Top = 30;
lb->Text = L"label" + Convert::ToString(indexNum);
tableLayoutPanel1->Controls->Add(pn, i, j);
indexNum++;
}
}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ s = "";
for (int i = 0; i < tableLayoutPanel1->Controls->Count; i++)
{
CheckBox^ cb = (CheckBox^)((Panel^)tableLayoutPanel1->Controls[i])->Controls[0];
Label^ lb = (Label^)((Panel^)tableLayoutPanel1->Controls[i])->Controls[1];
if (cb->Checked)
s = s + lb->Text + L" ";
}
MessageBox::Show(s);
}
};
}
我已经关注你了,你可以给我发信息。也可以在问题下留言。