irving926 稍嫌羞澀的路人
註冊時間: 2011-10-30 文章: 1
52.00 果凍幣
|
發表於: 2011-10-30, PM 2:35 星期日 文章主題: 求救 如何在.NET裡自定義類別? (附Form1.h) |
|
|
<Data.h檔>
using namespace System;
public ref class Datalab
{
public:
String^ topic;
String^ question;
int a_number; //挖了幾個空格
void initial(){array<String^>^ answer=gcnew array<String^>(50);}
};
<Form1.h檔>
#pragma once
#include "Data.h"
namespace 審計大補帖 {
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>
/// Form1 的摘要
///
/// 警告: 如果您變更這個類別的名稱,就必須變更與這個類別所依據之所有 .resx 檔案關聯的
/// Managed 資源編譯器工具的 'Resource File Name' 屬性。
/// 否則,這些設計工具
/// 將無法與這個表單關聯的當地語系化資源
/// 正確互動。
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: 在此加入建構函式程式碼
//
}
protected:
/// <summary>
/// 清除任何使用中的資源。
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::ComboBox^ comboBox1;
private: System::Windows::Forms::Button^ button4;
//private: System::Windows::Forms::CheckedListBox^ checkedListBox1;
protected:
private:
/// <summary>
/// 設計工具所需的變數。
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// 此為設計工具支援所需的方法 - 請勿使用程式碼編輯器修改這個方法的內容。
///
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->button3 = (gcnew System::Windows::Forms::Button());
this->label3 = (gcnew System::Windows::Forms::Label());
this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
this->button4 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// label1
//
this->label1->Font = (gcnew System::Drawing::Font(L"新細明體", 36, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(136)));
this->label1->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(255)), static_cast<System::Int32>(static_cast<System::Byte>(128)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(113, 264);
this->label1->Margin = System::Windows::Forms::Padding(7, 0, 7, 0);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(663, 212);
this->label1->TabIndex = 0;
this->label1->Text = L"Welcome to auditor,s heaven!";
//
// button1
//
this->button1->Location = System::Drawing::Point(136, 361);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(162, 77);
this->button1->TabIndex = 1;
this->button1->Text = L"start";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(404, 361);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(315, 77);
this->button2->TabIndex = 2;
this->button2->Text = L"may be sleep zzZZ";
this->button2->UseVisualStyleBackColor = true;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(156, 172);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(500, 22);
this->textBox1->TabIndex = 3;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(120, 76);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(242, 24);
this->label2->TabIndex = 3;
this->label2->Text = L"請輸入欲測驗的號次(請在輸入號次時空一格):";
this->label2->Click += gcnew System::EventHandler(this, &Form1::label2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(686, 172);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(102, 51);
this->button3->TabIndex = 3;
this->button3->Text = L"確定";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(254, 128);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(144, 24);
this->label3->TabIndex = 4;
this->label3->Text = L"ex:(21 23 45)";
//
// comboBox1
//
this->comboBox1->DropDownStyle = System::Windows::Forms::ComboBoxStyle::DropDownList;
this->comboBox1->FormattingEnabled = true;
this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(3) {L" 21 22 23 24 25", L" 26 27 28 29 30 31", L" 32 33 34 35 36 37"});
this->comboBox1->Location = System::Drawing::Point(229, 264);
this->comboBox1->Name = L"comboBox1";
this->comboBox1->Size = System::Drawing::Size(328, 20);
this->comboBox1->TabIndex = 3;
//
// button4
//
this->button4->Location = System::Drawing::Point(556, 264);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(100, 43);
this->button4->TabIndex = 3;
this->button4->Text = L"插入";
this->button4->UseVisualStyleBackColor = true;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(14, 24);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->ClientSize = System::Drawing::Size(853, 659);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->Font = (gcnew System::Drawing::Font(L"新細明體", 18, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(136)));
this->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"$this.Icon")));
this->Margin = System::Windows::Forms::Padding(7, 6, 7, 6);
this->Name = L"Form1";
this->Text = L"將此作品獻給楊炎杰老師";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
delete label1;
delete button2;
//new textBox1;
this->Controls->Add(this->textBox1);
this->Controls->Add(this->label2);
this->Controls->Add(this->label3);
this->Controls->Add(this->button3);
this->Controls->Add(this->comboBox1);
this->Controls->Add(this->button4);
//this->Controls->Add(this->checkedListBox1);
delete button1;
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) //第二個畫面的確定
{
String^ aha;
aha=textBox1->Text;
delete textBox1;
delete label2;
delete label3;
delete button3;
delete comboBox1;
delete button4;
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e)
{
int i=comboBox1->SelectedIndex;
switch(i)
{
case 0: //要去對應comboBox1的選項
textBox1->Text=String::Concat(textBox1->Text," 26 27");
case 1:
textBox1->Text=String::Concat(textBox1->Text," 26 27 28");
case 2:
textBox1->Text=String::Concat(textBox1->Text," 26 27 29");
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
array<Datalab^>^ data=gcnew array<Datalab^>(70);
data[0]->a_number=5;
data[0]->topic="一般公認審計準則";
data[0]->question="_______及_____";
}
};
}
complier說我data[0]->a_number=5; : 並未將物件參考設定為物件的執行個體 |
|