ProgressBar的連結 |
答題得分者是:Reignson
|
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
抱歉,以下是我的程式碼
void __fastcall TForm2::BitBtn1Click(TObject *Sender) { StatusBar1->SimpleText = "執行中"; for (int i = CGauge1->MinValue ; i < CGauge1->MaxValue ; i ) { Sleep(10); CGauge1->Progress ; } StatusBar1->SimpleText = "完成"; CGauge1->Progress = CGauge1->MinValue; } 但這段程式,需要點選BitBtn才能啟動CGauge 但是我希望是當Form1連到Form2時,CGauge能自動啟動 (關於ProgressBar這元件,最後改為使用CGauge) |
Reignson
一般會員 發表:3 回覆:11 積分:12 註冊:2005-01-31 發送簡訊給我 |
|
RaynorPao
版主 發表:139 回覆:3622 積分:7025 註冊:2002-08-12 發送簡訊給我 |
請參考以下的作法,再自行修改
(1)在 BCB 開發環境中,按「Project/Options/Forms」,確定「Form1」是「Main form」,「Form1」在「Auto create forms」欄位,「Form2」在「Available forms」欄位 (2)Form1 的程式碼如下(包含 Unit1.h 和 Unit1.cpp 兩個檔案的程式碼) [code cpp] // Unit1.h //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />//--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; void __fastcall Button1Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif // [code cpp] // Unit1.cpp //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { TForm2 *f2=new TForm2(Application); f2->ShowModal(); delete f2; } //--------------------------------------------------------------------------- [/code] (3)Form2 的程式碼如下(包含 Unit2.h 和 Unit2.cpp 兩個檔案的程式碼) [code cpp] // Unit2.h //--------------------------------------------------------------------------- #ifndef Unit2H #define Unit2H //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />#include "CGAUGES.h" #include //--------------------------------------------------------------------------- class TForm2 : public TForm { __published: // IDE-managed Components TCGauge *CGauge1; TTimer *Timer1; void __fastcall Timer1Timer(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm2(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm2 *Form2; //--------------------------------------------------------------------------- #endif // [code cpp] // Unit2.cpp //--------------------------------------------------------------------------- #include #pragma hdrstop #include "Unit2.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "CGAUGES" #pragma resource "*.dfm" TForm2 *Form2; //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { Timer1->Enabled=false; Timer1->Interval=1000; Timer1->Enabled=true; } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer1Timer(TObject *Sender) { Timer1->Enabled=false; for(int i=0; i<100; i ) { CGauge1->Progress=i 1; Sleep(100); Application->ProcessMessages(); } } //--------------------------------------------------------------------------- [/code]
------
-- 若您已經得到滿意的答覆,請適時結案!! -- -- 欲知前世因,今生受者是;欲知來世果,今生做者是 -- -- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 -- |
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
版主,你好
感謝,你給的程式,就是我想要做出來的樣子 想請問個問題,為什麼 在 Unit1.cpp的程式上面還要先宣告Unit1.h這一段程式 再來當我試著要把程式給加進我原本的程式裡卻發生錯誤 因為在FORM1這裡面原本就有一個Time的物件 當執行時一直出現Time的程式語法錯誤 TForm2 *f2=new TForm2(Application); f2->ShowModal(); delete f2; 請問 f2 是指什麼意思呢?? ===================引 用 RaynorPao 文 章=================== 請參考以下的作法,再自行修改 (1)在 BCB 開發環境中,按「Project/Options/Forms」,確定「Form1」是「Main form」,「Form1」在「Auto create forms」欄位,「Form2」在「Available forms」欄位 (2)Form1 的程式碼如下 |
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
|
Reignson
一般會員 發表:3 回覆:11 積分:12 註冊:2005-01-31 發送簡訊給我 |
先在Form2上點選,然後在C++ Builder左邊的Object Inspector上會看到Form2:TForm,在其下方有Events,
往下看會有OnShow欄位,在其上雙擊就會自動收出TForm2::FormShow(TObject *Sender)的函式定義,你可以在裡面直接呼叫Bitbtn1Click(Sender),但建議另外取名稱。 不過如果利用OnShow,只能看到ProgressBar執行結果,因為Form會在Bitbtn1Click結束後才顯示出,如果須要看到ProgressBar變化情形,理想方式還是像之前大大提到利用Timer方式。 例如: __fastcall TForm1::ExecProgress() { //ProgressBar1->Enabled 已設定為 false; StatusBar1->SimpleText = "執行中"; ProgressBar1->Step=1; ProgressBar1->Min=0; ProgressBar1->Max=10000; for (int i=0; i < ProgressBar1->Max; i ) { ProgressBar1->StepIt(); } StatusBar1->SimpleText = "完成"; } void __fastcall TForm1::BitBtn1Click(TObject *Sender) { ExecProgress(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Timer1->Enabled=false; ExecProgress(); } //--------------------------------------------------------------------------- ===================引 用 kill42el 文 章=================== 你好 請問你所指的 OnShow 是在哪個地方 我還是不太懂你的意思,可以麻煩在說詳細一點嗎?? ===================引 用 Reignson 文 章=================== 你的連結指的是由Form1去Create Form2嗎,如果是的話在Form2的OnShow上加上ProgressBar的控制,例如:ProgressBar1->Enabled=true。 |
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
你好
抱歉,關於你所說的Object Inspector 我找不到耶 只有Object Menultem 點下去是空白的 ===================引 用 Reignson 文 章=================== 先在Form2上點選,然後在C Builder左邊的Object Inspector上會看到Form2:TForm,在其下方有Events, 往下看會有OnShow欄位,在其上雙擊就會自動收出TForm2::FormShow(TObject *Sender)的函式定義,你可以在裡面直接呼叫Bitbtn1Click(Sender),但建議另外取名稱。 不過如果利用OnShow,只能看到ProgressBar執行結果,因為Form會在Bitbtn1Click結束後才顯示出,如果須要看到ProgressBar變化情形,理想方式還是像之前大大提到利用Timer方式。 例如: __fastcall TForm1::ExecProgress() { //ProgressBar1->Enabled 已設定為 false; StatusBar1->SimpleText = "執行中"; ProgressBar1->Step=1; ProgressBar1->Min=0; ProgressBar1->Max=10000; for (int i=0; i < ProgressBar1->Max; i ) { ProgressBar1->StepIt(); } StatusBar1->SimpleText = "完成"; } void __fastcall TForm1::BitBtn1Click(TObject *Sender) { ExecProgress(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender) { Timer1->Enabled=false; ExecProgress(); } |
Reignson
一般會員 發表:3 回覆:11 積分:12 註冊:2005-01-31 發送簡訊給我 |
|
kill42el
一般會員 發表:30 回覆:50 積分:16 註冊:2008-06-04 發送簡訊給我 |
|
Reignson
一般會員 發表:3 回覆:11 積分:12 註冊:2005-01-31 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |