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

TStringGrid上色與字串顯示的問題

答題得分者是:RaynorPao
wjlin
一般會員


發表:10
回覆:15
積分:5
註冊:2003-09-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-09-30 11:49:52 IP:61.13.xxx.xxx 未訂閱
如果我本身已經設定一個StringGrid1 row = 5 col = 2 fixed row = 0 fixed col = 1 我利用下列方式針對需要的區域上不同的背景色 並顯示字串
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
//在fixed cell上色
   if(ARow > 0 && ARow < 5 && ACol==0)
   {
      StringGrid1->Canvas->Brush->Color=0xccccff;
      StringGrid1->Canvas->FillRect(Rect);
      StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,
                                   StringGrid1->Cells[ARow][ACol]);
   }
//在一般cell上色
   if(ARow > 0 && ARow < 5 && ACol==1)
   {
      StringGrid1->Canvas->Brush->Color=0xffa090;
      StringGrid1->Canvas->FillRect(Rect);
      StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,
                                   StringGrid1->Cells[ARow][ACol]);
   }
}    另外在form形成的時候
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
//在fixed cell顯示字串
    StringGrid1->Cells[0][1] = "01";
    StringGrid1->Cells[0][3] = "03";
//在一般cell顯示字串
    StringGrid1->Cells[1][1] = "11";
    StringGrid1->Cells[1][3] = "13";
}
卻發現在fixed cell中 有上色的效果卻完全顯示不出字串 而在一般cell中只有第一個顯示字串正常 其他也是顯示不出字串 既使直接對grid cell輸入 也只有第一個cell會是正常的 不知道這是什麼問題 應該要如何解決呢?
RaynorPao
版主


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

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-09-30 12:27:16 IP:203.73.xxx.xxx 未訂閱
引言: 如果我本身已經設定一個StringGrid1 row = 5 col = 2 fixed row = 0 fixed col = 1 我利用下列方式針對需要的區域上不同的背景色 並顯示字串
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
//在fixed cell上色
   if(ARow > 0 && ARow < 5 && ACol==0)
   {
      StringGrid1->Canvas->Brush->Color=0xccccff;
      StringGrid1->Canvas->FillRect(Rect);
//      StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,
//                                   StringGrid1->Cells[ARow][ACol]);
   }
//在一般cell上色
   if(ARow > 0 && ARow < 5 && ACol==1)
   {
      StringGrid1->Canvas->Brush->Color=0xffa090;
      StringGrid1->Canvas->FillRect(Rect);
//      StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,
//                                   StringGrid1->Cells[ARow][ACol]);
   }
   StringGrid1->Canvas->TextOut(Rect.Left 2, Rect.Top 2,
                                StringGrid1->Cells[ACol][ARow]);
}    另外在form形成的時候
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
//在fixed cell顯示字串
//    StringGrid1->Cells[0][1] = "01";
//    StringGrid1->Cells[0][3] = "03";
//在一般cell顯示字串
//    StringGrid1->Cells[1][1] = "11";
//    StringGrid1->Cells[1][3] = "13";
   for(int i=0; i<5; i  )
   {
      for(int j=0; j<5; j  )
      {
         StringGrid1->Cells[i][j]="(" IntToStr(i) ", " IntToStr(j) ")";
      }
   }
}
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int ACol,
      int ARow, const AnsiString Value)
{
   StringGrid1->Cells[ACol][ARow]=Value;
}
卻發現在fixed cell中 有上色的效果卻完全顯示不出字串 而在一般cell中只有第一個顯示字串正常 其他也是顯示不出字串 既使直接對grid cell輸入 也只有第一個cell會是正常的 不知道這是什麼問題 應該要如何解決呢?
wjlin 你好: 試試看改成上面這樣子可不可以呢?? --
------
-- 若您已經得到滿意的答覆,請適時結案!! --
-- 欲知前世因,今生受者是;欲知來世果,今生做者是 --
-- 一切有為法,如夢幻泡影,如露亦如電,應作如是觀 --
wjlin
一般會員


發表:10
回覆:15
積分:5
註冊:2003-09-09

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-09-30 13:02:21 IP:61.13.xxx.xxx 未訂閱
真的非常感謝 情況似乎有改善 可以背景和文字同時顯示 但奇怪的是 對襯的cell也會一併顯示耶 例如 我只要cell[1][0]和cell[3][0]顯示 但cell[0][1]和cell[0][3]也會同時顯示 除了對角線上的不會有這個問題(00)(11)(22).... 我完全依照您的方式更改 也就是說textout這個應用 應該是要在所有上色的動作完成後 執行一次就行嗎? 另外 例如cell[2][0]沒有預設的字串顯示 而是保留使用者輸入 但依然會有 輸入完之後一離開這個cell 字串就看不到了的問題 這是不是有另外的技巧呢? 真的感謝
wjlin
一般會員


發表:10
回覆:15
積分:5
註冊:2003-09-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-09-30 13:56:50 IP:61.13.xxx.xxx 未訂閱
非常非常抱歉 我把textout上的col和row寫反了 改回來就正確了 感謝回覆
系統時間:2024-05-16 0:21:32
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!