如何從Form3呼叫Form1 |
答題得分者是:GrandRURU
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
Form3是主視窗Form1、Form2是次視窗
那要如何按Form3Button1去呼叫Form1的次視窗呢 請大大幫忙解答一下,在下是個新手 或是應該怎麼重新寫才好 [code cpp] #include #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] #include #pragma hdrstop #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { Form2->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm2::Button1Click(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Form3Button1Click(TObject *Sender) { ??????????????????? } //--------------------------------------------------------------------------- [/code]
------
-謝謝大大熱心的回覆!謝謝! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
[code cpp]
//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Form3Button1Click(TObject *Sender) { Form1->Show(); } //--------------------------------------------------------------------------- [/code]
編輯記錄
GrandRURU 重新編輯於 2008-04-21 13:21:09, 註解 無‧
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
請問大大按Form3Button1去呼叫Form1的次視窗 然後按Form1的Button1還能回到Form2 然後再按Form2的Button1還能回到Form3 這要怎麼寫呀
------
-謝謝大大熱心的回覆!謝謝! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
===================引 用 GrandRURU 文 章=================== 按照這個方式就可以以此類推了,如果還有遇到問題再提出來問吧 ===================引 用 l90425 文 章=================== 請問大大按Form3Button1去呼叫Form1的次視窗 然後按Form1的Button1還能回到Form2 然後再按Form2的Button1還能回到Form3 這要怎麼寫呀 Form3主視窗Form1、Form2次視窗 如果用以下的方法就無法讓Form1在一開始就出現要 如何讓Form1一開始就出現,而且Form3為主視窗呢? [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit2.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Form2->Show(); Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm2::Button1Click(TObject *Sender) { Form3->Show(); Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { Form1->Show(); } //--------------------------------------------------------------------------- [/code]
------
-謝謝大大熱心的回覆!謝謝! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
===================引 用 GrandRURU 文 章=================== Form3的onCreate事件中帶出Form1->Show()的方法,這樣就可以做到你所要求的了 會出現錯誤請問這是為什麼 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm3::FormCreate(TObject *Sender) { Form1->Show(); } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { Form1->Show(); } //--------------------------------------------------------------------------- [/code]
------
-謝謝大大熱心的回覆!謝謝! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈!
另外提供程式碼: [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { if(Form1) Form1 = new TForm1(Application); Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm3::FormActivate(TObject *Sender) { Button1Click(Sender); } //--------------------------------------------------------------------------- [/code] 再試試看 |
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
===================引 用 GrandRURU 文 章=================== 剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈! 另外提供程式碼: [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { if(Form1) Form1 = new TForm1(Application); Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm3::FormActivate(TObject *Sender) { Button1Click(Sender); } //--------------------------------------------------------------------------- [/code] 再試試看 成功了,實在太謝謝大大的用心指導了。3Q~
------
-謝謝大大熱心的回覆!謝謝! |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
===================引 用 l90425 文 章=================== ===================引 用 GrandRURU 文 章=================== 剛剛測了一下,哈哈,寫到不該寫入的記憶體了,但不知道為什麼,哈! 另外提供程式碼: [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit3.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { if(Form1) Form1 = new TForm1(Application); Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm3::FormActivate(TObject *Sender) { Button1Click(Sender); } //--------------------------------------------------------------------------- [/code] 再試試看 成功了,實在太謝謝大大的用心指導了。3Q~ 當Form2加入一個物件,如ComboBox有所選擇時會出現一個問題那就是 當按下 但 請問有辦法解決-謝謝
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-22 19:38:40, 註解 無‧
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
===================引 用 GrandRURU 文 章=================== 把你實際想要表現的流程畫一下,再對照你目前的程式碼,大概就可以知道要加什麼了 比方說: 如果checkbox勾選的話…該怎麼做… 就是 if(checkbox->………) xxx; else ooo; 這樣能懂嗎? 恩我懂 Form2裡面的物件有CheckBox1和CheckBox2和Button1 但是我的問題是 如果我選擇Form2的CheckBox1或CheckBox2時 並按下Button1時他會跳回Form1而不是Form3 但是如果不做選擇時按下Form2的Button1他會正常的跳會Form3 以下是我的程式碼 有辦法解決嗎-謝謝大大 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit2.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Form2->Show(); Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #ifndef Unit2H #define Unit2H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />#include //--------------------------------------------------------------------------- class TForm2 : public TForm { __published: // IDE-managed Components TButton *Button1; TCheckBox *CheckBox1; TCheckBox *CheckBox2; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm2(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm2 *Form2; //--------------------------------------------------------------------------- #endif [/code] [code cpp] #pragma hdrstop #include "Unit3.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm2::Button1Click(TObject *Sender) { Form3->Show(); Close(); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { if(Form1) Form1= new TForm1(Application); Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm3::FormActivate(TObject *Sender) { Button1Click(Sender); } //--------------------------------------------------------------------------- [/code]
------
-謝謝大大熱心的回覆!謝謝! |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
|
l90425
初階會員 發表:95 回覆:152 積分:49 註冊:2008-04-03 發送簡訊給我 |
我又試了其他的方法可以解決
如有更好的方法請大大再回覆給小弟-謝謝以上或以下大大的回答 參考 [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit3.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm3 *Form3; //--------------------------------------------------------------------------- __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm3::Button1Click(TObject *Sender) { if(Form1) Form1= new TForm1(Application); Form1->ShowModal(); } //--------------------------------------------------------------------------- void __fastcall TForm3::FormShow(TObject *Sender) { Button1Click(Sender); } //--------------------------------------------------------------------------- [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit2.h" #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { Form2->ShowModal(); Close(); } //--------------------------------------------------------------------------- [/code]
------
-謝謝大大熱心的回覆!謝謝!
編輯記錄
l90425 重新編輯於 2008-04-24 10:11:12, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |