關於[bcb]StringGrid1DrawCell使用問題? |
尚未結案
|
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
[bcb]
1.我想請問各位 void __fastcall TForm1::mapview(char *bin,int x,int yy) { char *ptr=bin,a[10]; for(int i=1;i<=x;i ){ for(int j=0;j<=3;j ) a[j]=*ptr ; StringGrid1->Cells[i][yy]=atoi(a); if(StringGrid1->Cells[i][yy]==0)<----我想吧=0的格子都變成黑色的 } } 我該如何用,我目前知道StringGrid1DrawCell可以改變格子顏色,但不知道要著麼放參數進去StringGrid1DrawCell(?,int,int,?,?); void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { if (ACol ==1 && ARow==1) { StringGrid1->Canvas->Brush->Color=clGreen; StringGrid1->Canvas->FillRect(Rect); StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,StringGrid1->Cells[ACol][ARow]); } } //----------------------------------------------------------------------------------------- 2.我想在問int wafer[25][100][100] 可以放到StringGrid1->Cells[100][100]裡面秀出來嗎?? 比如說wafer[1][100][100] 放入StringGrid1->Cells[100][100]顯示出來,利用選擇的方式[1-25]
------
加油吧 C 編輯記錄
taishyang 重新編輯於 2007-07-03 10:00:19, 註解 無‧
|
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
看見DrawCell的參數以及你範例中的寫法沒?這個程序是在StringGrid重繪的時候被自動呼叫的,所以改變Cell的格子顏色以及填入文字都在這個函數裡面處理。看一下以下的範例,把填字與填色的部分綜合一下!
http://delphi.ktop.com.tw/board.php?cid=30&fid=69&tid=88393 |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
下面這是我的程式,我是從c++改過來的
我知道StringGrid1DrawCell會一直重繪但是我只想要他在第一次我在存入StringGrid1->Cells的時候就把顏色畫好, 不然在拉bar的時候速度非常慢,我想請問可以讓他在第1次存入之後就不重繪嗎?? //--------------------------------------------------------------------------- #include #include #include #include #pragma hdrstop #include "loadmap.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { OpenDialog1->Execute(); for(int j = 1; j<=StringGrid1->RowCount; j ) for(int i =1; i<=StringGrid1->ColCount; i ) StringGrid1->Cells[i][j]=""; FILE *ifp; char bin[1000],filename[50]; Label1->Caption=OpenDialog1->FileName; AnsiString str=AnsiString(filename); int Horizontal,Vertical,y=0,yy=1,xx=0,i; if((ifp= fopen(OpenDialog1->FileName.c_str(),"r")) == NULL){ printf("file not open or find"); getchar(); exit(1); } while(fscanf(ifp,"%s",bin)!=EOF){ if(strcmp("[WaferMapBegin]",bin)==0){ while(fscanf(ifp,"%s",bin)!=EOF){ fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin); Horizontal=atoi(bin); fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin); Vertical=atoi(bin); fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin);//XIncreament fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin); fscanf(ifp,"%s",bin);//YIncreament //printf("%s\n%s",XIncreament,YIncreament); break; } while(fscanf(ifp,"%s",bin)!=EOF){ if((strcmp(" ",bin)==0)&xx==0){ while(fscanf(ifp,"%s",bin)!=EOF){ if(strcmp(" ",bin)==0) break; xx ; } } if(strcmp("|",bin)==0){ fgets(bin,200,ifp); mapview(bin,xx,yy); y ; yy ; } } } } fclose(ifp); StringGrid1->Cells[0][0]="Y/X"; for(i=y;i>=1;i--) StringGrid1->Cells[0][i]=Horizontal ; for(i=1;i<=xx;i ) StringGrid1->Cells[i][0]=Vertical ; StringGrid1->ColCount=xx; StringGrid1->RowCount=yy; StringGrid1->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TForm1::mapview(char *bin,int x,int yy) { char *ptr=bin,a[10]; for(int i=1;i<=x;i ){ for(int j=0;j<=3;j ) a[j]=*ptr ; StringGrid1->Cells[i][yy]=atoi(a); } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { for(int i=1;i<=StringGrid1->ColCount;i ){ for(int j=1;j<=StringGrid1->RowCount;j ){ if(StringGrid1->Cells[i][j]==0) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clBlack; StringGrid1->Canvas->FillRect(Rect); } if(StringGrid1->Cells[i][j]==1) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clLime; StringGrid1->Canvas->FillRect(Rect); StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,StringGrid1->Cells[ACol][ARow]); } } } } //---------------------------------------------------------------------------
------
加油吧 C |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
//像我發得這樣嗎??謝謝大大提示
下面這是我的程式,我是從c 改過來的 我知道StringGrid1DrawCell會一直重繪但是我只想要他在第一次我在存入StringGrid1->Cells的時候就把顏色畫好, 不然在拉bar的時候速度非常慢,我想請問可以讓他在第1次存入之後就不重繪嗎?? <textarea cols="60" rows="10" class="cpp" name="code"> //像我發得這樣嗎?? //--------------------------------------------------------------------------- #include
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我不太懂this->NeedRedraw = true;這段是在哪裡設定,是在*.h那裡加嗎??
===================引 用 Stallion 文 章=================== 你困在自己的迷失裡面了~這個問題很簡單啊~ 加個類別的Public 布林值在類別裡面,於第一次進入該函數時設定為假,即可判斷需不需要在DrawCell。 1.在FormCreate時設定 this->NeedRedraw = true; 2在DrawCelll裡面寫下 if ( this->NeedRedraw ) { ...... this->NeedRedraw = false; } 3.這樣在第一次DrawCell後就不會再重繪了。
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
這是在類別中自己加上的公共變數,不是已說明了嗎!可以在FormCreate時初始化。
===================引 用 BON362 文 章=================== 我不太懂this->NeedRedraw = true;這段是在哪裡設定,是在*.h那裡加嗎?? ===================引 用 Stallion 文 章=================== 你困在自己的迷失裡面了~這個問題很簡單啊~ 加個類別的Public 布林值在類別裡面,於第一次進入該函數時設定為假,即可判斷需不需要在DrawCell。 1.在FormCreate時設定 this->NeedRedraw = true; 2在DrawCelll裡面寫下 if ( this->NeedRedraw ) { ...... this->NeedRedraw = false; } 3.這樣在第一次DrawCell後就不會再重繪了。 |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我試試看你可以在我的程式碼裡面加那段給我看嗎??我還是不太懂
===================引 用 Stallion 文 章=================== 這是在類別中自己加上的公共變數,不是已說明了嗎!可以在FormCreate時初始化。 ===================引 用 BON362 文 章=================== 我不太懂this->NeedRedraw = true;這段是在哪裡設定,是在*.h那裡加嗎?? ===================引 用 Stallion 文 章=================== 你困在自己的迷失裡面了~這個問題很簡單啊~ 加個類別的Public 布林值在類別裡面,於第一次進入該函數時設定為假,即可判斷需不需要在DrawCell。 1.在FormCreate時設定 this->NeedRedraw = true; 2在DrawCelll裡面寫下 if ( this->NeedRedraw ) { ...... this->NeedRedraw = false; } 3.這樣在第一次DrawCell後就不會再重繪了。
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
BCB的Form類別不是都有一個同名的Header File嗎?
1.在該Header File檔案中(如果叫做TForm1.hpp) 的Public或Private部分加上一個布林值如 bool NeedRedraw; 2.在Form的程式碼檔案部分(如果叫做TForm1.cpp),以Object Inspector的方式加入Form Create的事件並加入程式碼。 void __fastcall TForm1::FormCreate(TObject *Sender) { this->NeedRedraw = true; } 3.其後就在重繪完的函式部分,再設定 this->NeedRedraw = false。 if ( this->NeedRedraw ) { //...... your code this->NeedRedraw = false; } 4.對於類別,建議BON362兄可以再翻閱一下C++的書籍,爾後才可以善用類別。 |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我知道你說的方法了這樣用對吧,但是我這樣子用他連畫都不會畫><
<textarea cols="60" rows="10" class="cpp" name="code"> if(this->NeedRedraw == true){ for(int i=1;i<=StringGrid1->ColCount;i ){ for(int j=1;j<=StringGrid1->RowCount;j ){ if(StringGrid1->Cells[i][j]==0) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clBlack; StringGrid1->Canvas->FillRect(Rect); } if(StringGrid1->Cells[i][j]==1) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clLime; StringGrid1->Canvas->FillRect(Rect); StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,StringGrid1->Cells[ACol][ARow]); } } } this->NeedRedraw = false; }</textarea>
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我加入進去了,可以編譯應該是ok,但我把this->NeedRedraw = false;這段mask就繪出,但這樣就會重繪><
<textarea cols="60" rows="10" class="cpp" name="code"> void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { if(this->NeedRedraw == true){ for(int j=1;j<=StringGrid1->RowCount;j ) for(int i=1;i<=StringGrid1->ColCount;i ) { StringGrid1->Cells[i][j]=wafer[0][i][j]; //wafer[0][i][j]是我讀入的data(AnsiString wafer[25][100][100]) if(StringGrid1->Cells[i][j]==0) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clBlack; StringGrid1->Canvas->FillRect(Rect); } if(StringGrid1->Cells[i][j]==1) if (ACol ==i && ARow==j){ StringGrid1->Canvas->Brush->Color=clLime; StringGrid1->Canvas->FillRect(Rect); StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,StringGrid1->Cells[ACol][ARow]); } } this->NeedRedraw = false; } //------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TStringGrid *StringGrid1; TOpenDialog *OpenDialog1; TLabel *Label1; TLabel *Label2; TComboBox *ComboBox1; TButton *Button2; TButton *Button3; TButton *Button4; void __fastcall Button1Click(TObject *Sender); void __fastcall StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State); void __fastcall ComboBox1Change(TObject *Sender); void __fastcall StringGrid1SelectCell(TObject *Sender, int ACol, int ARow, bool &CanSelect); void __fastcall Button3Click(TObject *Sender); void __fastcall Button4Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); private: void __fastcall TForm1::mapview(char *bin,int x,int yy); // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); bool NeedRedraw;//這裡對吧 AnsiString wafer[25][100][100]; int w; }; //------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { this->NeedRedraw = true;//初值 } </textarea> ===================引 用 Stallion 文 章=================== 你確定FormCreate裡面的初始設定值你加上去了嗎?把上一篇看清楚一下。
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
1.可能原因是FormCreate時,把位於其上的元件也初始化,因此造成你的StringGrid還未讀入資料時已經先重繪過一次了。
2.可能解決方案加入一個自訂的整數Counter也於FormCreate時初始化為0,原來的布林值去掉。當進入重繪時Counter加1,TRACE看看Counter是到多少的時候你的資料已經載入完畢,此時Counter的值就是臨界值,當Counter大於這個臨界值時就不重繪。 3.其他我想不出更好的方法讓StringGrid於適當時間不呼叫這個函數,看看其他先進有無方法?! |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
真是太謝謝你了,你給我提示我會在試試看.
還有一個問題就是wafer[25][100][100] 裡面有26組100*100的矩陣 我想利用StringGrid1->Cells[100][100]來顯示我要的數值但是第二組放的位子有點怪怪的, wafer[0][100][100].第一組結果 photo.xuite.net/bon362/1839963/1.jpg wafer[1][100][100].第2組結果 photo.xuite.net/bon362/1839963/2.jpg <textarea cols="60" rows="10" class="cpp" name="code"> //都是從[1][1]開始 //顯示第一組 for(int j=1;j<=StringGrid1->RowCount;j ) for(int i=1;i<=StringGrid1->ColCount;i ) StringGrid1->Cells[i][j]=wafer[0][i][j]; //顯示第二組 for(int j=1;j<=StringGrid1->RowCount;j ) for(int i=1;i<=StringGrid1->ColCount;i ) StringGrid1->Cells[i][j]=wafer[1][i][j]; </textarea>
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
C language base index begins from Zero, therefore, to fetch each element from wafer[25][100][100], the indexes are "wafer[0 to 24][0 to 99][0 to 99]".
*sorry, I am using linux, and my chinese-input method malfuntions, hope you can understand what I mean. |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我現在圖傳不上去,等等晚一點傳上去,你就懂我我的問題了,我知道0開始跑,我是要從1*1開始,麻煩你了
我上圖片上傳好了,可以麻煩你幫我看一下嗎QQ ===================引 用 Stallion 文 章=================== C language base index begins from Zero, therefore, to fetch each element from wafer[25][100][100], the indexes are "wafer[0 to 24][0 to 99][0 to 99]". *sorry, I am using linux, and my chinese-input method malfuntions, hope you can understand what I mean.
------
加油吧 C
編輯記錄
BON362 重新編輯於 2007-07-05 18:21:28, 註解 無‧
|
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
|
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
還有Online help是哪個說明檔嗎??
這樣算清掉嗎?? <textarea cols="60" rows="10" class="cpp" name="code"> for(int j = 1; j<=StringGrid1->RowCount; j ) for(int i =1; i<=StringGrid1->ColCount; i ) StringGrid1->Cells[i][j]=""; </textarea> ===================引 用 Stallion 文 章=================== TStringGrid很久沒用了,如果記得沒錯的話,有個Col以及Row屬性,控制著填入資料的欄位索引,你在填過資料後這兩個直會變動,必須將他重設定才可,你查一下Online Help即可知道。
------
加油吧 C |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
1.點選TStringGrid元件,按F1就可以得到說明。
2.可以這樣清理,可是控制Row及Col屬性是必要的。 ===================引 用 BON362 文 章=================== 還有Online help是哪個說明檔嗎?? 這樣算清掉嗎?? <textarea name="code" class="cpp" rows="10" cols="60"> for(int j = 1; j<=StringGrid1->RowCount; j ) for(int i =1; i<=StringGrid1->ColCount; i ) StringGrid1->Cells[i][j]=""; </textarea> ===================引 用 Stallion 文 章=================== TStringGrid很久沒用了,如果記得沒錯的話,有個Col以及Row屬性,控制著填入資料的欄位索引,你在填過資料後這兩個直會變動,必須將他重設定才可,你查一下Online Help即可知道。 |
BON362
一般會員 發表:3 回覆:16 積分:13 註冊:2007-05-28 發送簡訊給我 |
我在想假如我利用void __fastcall TForm1::StringGrid1DrawCell來控制Row Col會不會造成一直重複清除
我在想這問題可能是我讀資料到wafer[25][100][100]有異常 剛剛我發現我有一段寫錯了><真對不起造成你的困擾,重繪問題我再找找看, ===================引 用 Stallion 文 章=================== 1.點選TStringGrid元件,按F1就可以得到說明。 2.可以這樣清理,可是控制Row及Col屬性是必要的。 ===================引 用 BON362 文 章=================== 還有Online help是哪個說明檔嗎?? 這樣算清掉嗎?? <textarea cols="60" rows="10" class="cpp" name="code"> for(int j = 1; j<=StringGrid1->RowCount; j ) for(int i =1; i<=StringGrid1->ColCount; i ) StringGrid1->Cells[i][j]=""; </textarea> ===================引 用 Stallion 文 章=================== TStringGrid很久沒用了,如果記得沒錯的話,有個Col以及Row屬性,控制著填入資料的欄位索引,你在填過資料後這兩個直會變動,必須將他重設定才可,你查一下Online Help即可知道。
------
加油吧 C |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |