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

StringGrid上色

答題得分者是:brook
zx4654
一般會員


發表:18
回覆:26
積分:8
註冊:2005-04-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-08 17:27:04 IP:118.170.xxx.xxx 訂閱
我看了很多前輩的程式,也試了一試,大致了解,可是我的問題是,我只想在我要的Cell上填色,然後滑鼠就算點到其他的也不會再上色,請問要如何寫?
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-04-09 07:51:19 IP:118.168.xxx.xxx 訂閱

[code cpp]
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ACol == StringGrid1->Col && ARow == StringGrid1->Row)
{
StringGrid1->Canvas->Brush->Color = clRed;
StringGrid1->Canvas->FillRect( Rect );
StringGrid1->Canvas->TextOut( Rect.Left 2, Rect.Top 2, StringGrid1->Cells[ACol][ARow]);
}
}
[/code]
1.以上是Cells填上顏色的範例,StringGrid的OnDrawCell.
2.至於要在哪個Cells自己去設個值取代StringGrid1->Col和StringGrid1->Row.
zx4654
一般會員


發表:18
回覆:26
積分:8
註冊:2005-04-05

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-04-09 08:33:05 IP:118.170.xxx.xxx 訂閱

===================引 用 brook 文 章===================

[code cpp]
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if (ACol == StringGrid1->Col && ARow == StringGrid1->Row)
{
StringGrid1->Canvas->Brush->Color = clRed;
StringGrid1->Canvas->FillRect( Rect );
StringGrid1->Canvas->TextOut( Rect.Left 2, Rect.Top 2, StringGrid1->Cells[ACol][ARow]);
}
}
[/code]
StringGrid1->Canvas->TextOut( Rect.Left 2, Rect.Top 2, StringGrid1->Cells[ACol][ARow]);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
可以請問這裡是什麼意思嗎?(Rect.Left是什麼,為什麼+2)

非常感謝你的指導!
編輯記錄
zx4654 重新編輯於 2008-04-09 08:34:48, 註解 無‧
zx4654 重新編輯於 2008-04-09 08:35:43, 註解 無‧
zx4654 重新編輯於 2008-04-09 08:36:41, 註解 無‧
zx4654 重新編輯於 2008-04-09 08:37:32, 註解 無‧
zx4654 重新編輯於 2008-04-09 08:38:40, 註解 無‧
zx4654 重新編輯於 2008-04-09 08:39:37, 註解 無‧
brook
資深會員


發表:57
回覆:323
積分:371
註冊:2002-07-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-04-09 10:34:51 IP:118.168.xxx.xxx 訂閱
StringGrid1->Canvas->TextOut( Rect.Left 2, Rect.Top 2, StringGrid1->Cells[ACol][ARow]);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
可以請問這裡是什麼意思嗎?(Rect.Left是什麼,為什麼+2)

1.Rect表示該Cells的位置區域範圍.
2. 2只是要字左邊空2點,上面空2點,可能看起來比較放在中間而己,至於怎樣會比較好看,則需考慮字高和字寛以及Rect的區域.
系統時間:2024-05-02 23:14:49
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!