電腦遊戲製作開發設計論壇 首頁 電腦遊戲製作開發設計論壇
任何可以在PC上跑的遊戲都可以討論,主要以遊戲之製作開發為主軸,希望讓台灣的遊戲人有個討論、交流、教學、經驗傳承的園地
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入 

Google
求救 如何在.NET裡自定義類別? (附Form1.h)

 
發表新主題   回覆主題    電腦遊戲製作開發設計論壇 首頁 -> 遊戲程式中級班:資料結構、Win32 API、各種視窗函式庫
上一篇主題 :: 下一篇主題  
發表人 內容
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; : 並未將物件參考設定為物件的執行個體
回頂端
檢視會員個人資料 發送私人訊息
yag
Site Admin


註冊時間: 2007-05-02
文章: 688

2673.35 果凍幣

發表發表於: 2011-10-30, PM 2:56 星期日    文章主題: Re: 求救 如何在.NET裡自定義類別? (附Form1.h) 引言回覆

我不會.NET,但看起來是你那70個data要gcnew Datalab;才行
用個迴圈把它全部new過一遍試試吧
回頂端
檢視會員個人資料 發送私人訊息 發送電子郵件
chanjoey
偶而上來逛逛的過客


註冊時間: 2015-08-27
文章: 12
來自: 新北市
213.97 果凍幣

發表發表於: 2015-8-27, PM 7:12 星期四    文章主題: 求救 如何在.NET裡自定義類別? (附Form1.h) 引言回覆

.NET在國內的教學並不熱門,
這是因為國人常常貼了程式碼卻得不到解答。
事實上.NET是一項工業技術,
在西方先進國家,
這一類技術的學習都是要透過視訊教學才能解答問題的。
要做好.NET的學習,
首先要做好下列的幾項準備工作:
1.買一台DV攝影機來錄影電腦畫面。
如果你的預算不夠,
買一台有錄影功能的數位相機或是智慧手機來錄影都可以。
2.把電腦螢幕解析度調整到800X600或是640X480。
顯示螢幕如果可以字大一點,
比較不容易傷眼,
你就可以學久一點。
有些網站建議自定義Visual C++的字體顏色,
你也可以參考使用這些自定義的顏色組合,
網友推薦的顏色組合通常比較不傷眼。

至於你的問題的解答,有下列幾個方式可以解決:
1.Visual C++是一個工業軟體,
可以到微軟網站問微軟人員請求協助。

2.在FORM程式如果要創建一個class的方法如下:
按下"專案"-->"加入類別",
點選"C++",
利用泛型C++類別精靈來完成這項類別的設定。
你將需要填寫一個表單,
要填上你的類別名稱,.h檔名稱,.cpp檔名稱,
基底類別也要填寫。
可以改變存取的方式,
public是公開的類別,
private是私有類別,
依照你的情況來使用。

3.最後,安排你的程式碼,
要注意每一個加入的class都要使用按下"專案"-->"加入類別",
否則自己打進去的public class Myclass這種打字方式,
系統是不會讀取的,
要按下"專案"-->"加入類別",
編譯器才會知道你有加入類別。
Visual C++是一套工業軟體,
所以你不按鈕的話,光是打字他是不會跑的。

最後,歡迎網友補充說明其他的注意事項。
回頂端
檢視會員個人資料 發送私人訊息
從之前的文章開始顯示:   
發表新主題   回覆主題    電腦遊戲製作開發設計論壇 首頁 -> 遊戲程式中級班:資料結構、Win32 API、各種視窗函式庫 所有的時間均為 台灣時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
可以 在這個版面附加檔案
可以 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作