0
我需要幫助才能找出可用於將自定義數量的標籤添加到Windows窗體的代碼。我正在使用默認的Windows Forms應用程序項目進行測試。我找出我的代碼的方式可能會起作用,如果我使用一個對象數組並在特定位置添加循環來迭代每個聲明。如何在VC++中將多個標籤添加到表單中?
這是我到目前爲止,我真的不知道如何使程序識別smartLabel陣列,請幫助。
#pragma once
namespace gui {
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();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ smartLabel[0]; //INSERTED FOR POSSIBLE SOLUTION
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->label1 = (gcnew System::Windows::Forms::Label());
this->smartLabel[0] = (gcnew System::Windows::Forms::Label());//INSERTED FOR POSSIBLE SOLUTION
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(10, 10);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(50, 15);
this->label1->TabIndex = 0;
this->label1->Text = L"label1";
//
// smartLabel[0]
//
this->smartLabel[0]->AutoSize = true; //INSERTED FOR POSSIBLE SOLUTION
this->smartLabel[0]->Location = System::Drawing::Point(30, 10); //INSERTED FOR POSSIBLE SOLUTION
this->smartLabel[0]->Name = L"label2"; //INSERTED FOR POSSIBLE SOLUTION
this->smartLabel[0]->Size = System::Drawing::Size(50, 15); //INSERTED FOR POSSIBLE SOLUTION
this->smartLabel[0]->TabIndex = 0; //INSERTED FOR POSSIBLE SOLUTION
this->smartLabel[0]->Text = L"label2"; //INSERTED FOR POSSIBLE SOLUTION
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); //INSERTED FOR POSSIBLE SOLUTION
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; //INSERTED FOR POSSIBLE SOLUTION
this->ClientSize = System::Drawing::Size(550, 498); //INSERTED FOR POSSIBLE SOLUTION
this->Controls->Add(this->label1);
this->Controls->Add(this->smartLabel[0]); //INSERTED FOR POSSIBLE SOLUTION
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
};
}