全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1090
推到 Plurk!
推到 Facebook!

StringGrid的格子是否只能塞一行的字而已?!

尚未結案
bonnie.fan
一般會員


發表:6
回覆:1
積分:1
註冊:2003-10-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-10-08 14:35:44 IP:210.62.xxx.xxx 未訂閱
我想將"作業系統謝景順"變成 作業系統 謝景順 但是我也加過換行的指令ex:#10#13 只能空格而已,不能換行;是否StringGrid的格子只能塞一行的字?! 如果真的是的話,那麼我該怎麼辦?!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-10-08 14:45:21 IP:147.8.xxx.xxx 未訂閱
Draw the text yourself in the OnDrawCell event (e.g. DrawText API).
jason_cyl329
高階會員


發表:123
回覆:155
積分:105
註冊:2003-05-26

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-10-08 15:08:43 IP:61.218.xxx.xxx 未訂閱
請參考我前一個發表的方法,這樣所抓到的Rect你想用幾行都行, 只要cell夠寬
pgdennis
資深會員


發表:41
回覆:526
積分:443
註冊:2002-05-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-10-08 15:21:15 IP:218.163.xxx.xxx 未訂閱
以前在網路找的,直接co過去用就行了...應該不用改  
 
procedure TFMT3020101.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
   StringPart,
   NumberPart: String;
   Width,Width2: Integer;      {width of the numerical part of our string}
   LeftOffset: Integer; {Left offset of the right justified text}
   SecondLine: Integer; {vertical position of line 2 }
const
   Margin = 2;
begin
   //if ARow=1 then begin{只處理title}
     {extract the first word of the cell's text}
     StringPart := Copy(StringGrid1.Cells[ACol, ARow], 1,
                                     Pos(' ', StringGrid1.Cells[ACol, ARow])-1);
     {extract the numerical part of the cell's text}
     NumberPart := Copy(StringGrid1.Cells[ACol, ARow],
                       Length(StringPart) 1, Length(StringGrid1.Cells[ACol, ARow]));
     {What it the width of the text of the number?}
     Width := StringGrid1.Canvas.TextWidth(NumberPart);
     Width2 := StringGrid1.Canvas.TextWidth(StringPart);
     {Where do we position line 2?}
     SecondLine := Rect.Top   ((Rect.Bottom - Rect.Top) div 2);
     LeftOffset := Rect.Right - Width - Margin;
     {blank out the cell}
     StringGrid1.Canvas.FillRect(Rect);
     {draw the first line of text (the string part) at the top of the cell}
     StringGrid1.Canvas.TextOut(Rect.Left 30 Margin, Rect.Top Margin, StringPart);
    //StringGrid1.Canvas.TextOut(StringGrid1.ColWidths[ACol]-(Width2 div 2), Rect.Top Margin, StringPart);
     {draw the number part on line 2 but also right justify it}
     StringGrid1.Canvas.TextOut(LeftOffset, SecondLine, NumberPart);    end;
永遠追不上技術更新的速度 發表人 -
------
星期一,二...無窮迴圈@@
Mickey
版主


發表:77
回覆:1882
積分:1390
註冊:2002-12-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-10-08 21:48:09 IP:218.32.xxx.xxx 未訂閱
題外話...Windows Base 的換行的字元, 應該是 #13#10 另外
系統時間:2024-05-19 6:52:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!