線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2779
推到 Plurk!
推到 Facebook!

ProgressBar的連結

答題得分者是:Reignson
kill42el
一般會員


發表:30
回覆:50
積分:16
註冊:2008-06-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-07-22 12:47:31 IP:210.71.xxx.xxx 訂閱
你好 
我想要請問的事,當我有兩個Form。
Form1 跟 Form2
當我的Form1連接到Form2時
一連結到時,在Form2上的ProgressBar 會馬上啟動
請問,這樣要如何去宣告

taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-07-22 19:41:17 IP:118.169.xxx.xxx 訂閱
請PO出您測試的程式碼讓前輩們看看問題在哪邊 ^_^
kill42el
一般會員


發表:30
回覆:50
積分:16
註冊:2008-06-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-07-23 12:03:58 IP:210.71.xxx.xxx 訂閱
抱歉,以下是我的程式碼
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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-07-23 12:03:58 IP:220.130.xxx.xxx 訂閱
你的連結指的是由Form1去Create Form2嗎,如果是的話在Form2的OnShow上加上ProgressBar的控制,例如:ProgressBar1->Enabled=true。
RaynorPao
版主


發表:139
回覆:3622
積分:7025
註冊:2002-08-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-07-23 12:36:53 IP:210.208.xxx.xxx 訂閱
請參考以下的作法,再自行修改
(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]

//

[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]

//

[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]
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
編輯記錄
RaynorPao 重新編輯於 2008-07-23 15:28:39, 註解 無‧
RaynorPao 重新編輯於 2008-07-23 15:33:24, 註解 無‧
RaynorPao 重新編輯於 2008-07-23 15:37:38, 註解 無‧
RaynorPao 重新編輯於 2008-07-23 15:38:58, 註解 無‧
kill42el
一般會員


發表:30
回覆:50
積分:16
註冊:2008-06-04

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-07-23 15:25:27 IP:210.71.xxx.xxx 訂閱
版主,你好
感謝,你給的程式,就是我想要做出來的樣子
想請問個問題,為什麼
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 重新編輯於 2008-07-23 23:11:34, 註解 無‧
kill42el 重新編輯於 2008-07-24 15:23:44, 註解 無‧
kill42el
一般會員


發表:30
回覆:50
積分:16
註冊:2008-06-04

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-07-24 15:28:22 IP:210.71.xxx.xxx 訂閱
你好
請問你所指的 OnShow 是在哪個地方
我還是不太懂你的意思,可以麻煩在說詳細一點嗎??
===================引 用 Reignson 文 章===================
你的連結指的是由Form1去Create Form2嗎,如果是的話在Form2的OnShow上加上ProgressBar的控制,例如:ProgressBar1->Enabled=true。
Reignson
一般會員


發表:3
回覆:11
積分:12
註冊:2005-01-31

發送簡訊給我
#8 引用回覆 回覆 發表時間:2008-07-24 18:01:00 IP:220.130.xxx.xxx 訂閱
先在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

發送簡訊給我
#9 引用回覆 回覆 發表時間:2008-07-30 11:38:23 IP:210.71.xxx.xxx 訂閱
你好
抱歉,關於你所說的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

發送簡訊給我
#10 引用回覆 回覆 發表時間:2008-07-31 10:10:44 IP:220.130.xxx.xxx 訂閱
下圖是BC5的畫面。

kill42el
一般會員


發表:30
回覆:50
積分:16
註冊:2008-06-04

發送簡訊給我
#11 引用回覆 回覆 發表時間:2008-07-31 14:41:43 IP:210.71.xxx.xxx 訂閱
謝謝
但是,看不到圖耶
那可以給我,你的及時通或是MSN
這樣比較方便請教你
===================引 用 Reignson 文 章===================
下圖是BC5的畫面。

Reignson
一般會員


發表:3
回覆:11
積分:12
註冊:2005-01-31

發送簡訊給我
#12 引用回覆 回覆 發表時間:2008-07-31 17:31:28 IP:220.130.xxx.xxx 訂閱
按下快捷鍵[F11]即可看到。
系統時間:2024-04-25 16:54:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!