用stringgrid控件合併標題欄單元格的問題? |
尚未結案
|
delphihelp
一般會員 發表:1 回覆:1 積分:0 註冊:2008-07-08 發送簡訊給我 |
用stringgrid控件,比如為5行6列。有2行固定標題欄,單元格内容為可修改。比如想要第0行中第0列到4列合併單元格,第0行中第5列到第6列
合併單元格。所有單元格中的文字為居中。 現在發現做的時候總是不很完善。虽然也能合并,但是縂有這樣那樣的問題。要麽是合併后的單元格文字不知取具體哪一個單元格内容。要麽在 stringgrid的cell中点击时发现合并的单元格的文字内容不见等(似乎重绘了).要么标题栏的文字不能居中或者顯示不全。 請幫忙看下代碼,不知關鍵的地方怎麽寫? procedure TForm1.FormShow(Sender: TObject); begin StringGrid1.DefaultDrawing :=False; stringgrid1.DefaultColWidth:=33; stringgrid1.FixedRows:=2; StringGrid1.Cells[0,0] := 'aaaaaaaaaaaa';//此處設置標題欄中合併單元格第0列到4列的内容 因不知道取哪一個格子,还是cells[4,0]? StringGrid1.Cells[5,0] := 'bb';//此處設置標題欄中合併單元格的第5列到第6列内容 //..... end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with StringGrid1.Canvas do begin if ((acol=0) ) and ((ARow=0) )then if ((acol=4) ) and ((ARow=0) )then rect.Right:=rect.Right; //不知这里如何写? //合併0行中第5列到6列 if ((acol=5) ) and ((ARow=0) )then // rect.Right:=rect.Right rect.Right-rect.Left; rect.Right:=rect.Right 33; if ((acol=6) ) and ((ARow=0) )then rect.Left:=rect.Right ; //不知这里如何写? if gdFixed in State then Brush.Color := StringGrid1.FixedColor; FillRect(Rect); with StringGrid1 do TextRect(Rect, Rect.Left 2, Rect.Top 2, Cells[ACol, ARow]); // if gdFixed in State then DrawEdge(Handle, Rect, BDR_RAISEDINNER, BF_RECT); end; //标题栏的第0行需要合并单元格,第1行需要竖行显示,其他均居中 if (arow=1) then begin with StringGrid1 do with Canvas do begin FillRect(Rect); DrawText(Handle, PChar(Cells[ACol, ARow]), Length(Cells[ACol, ARow]), Rect, DT_VCENTER or DT_CENTER or DT_WORDBREAK ); end; end else begin StringGrid1.Canvas.FillRect(Rect); DrawText(StringGrid1.Canvas.Handle, pChar(StringGrid1.Cells[ACol,ARow]), Length(StringGrid1.Cells[ACol,ARow]), Rect, DT_CENTER or DT_SINGLELINE or DT_VCENTER); end; end; procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean); begin stringgrid1.options := stringgrid1.options [goEditing]; end; 不知以上代碼怎麽修改? 還請多多幫助。 編輯記錄
delphihelp 重新編輯於 2008-07-14 17:03:48, 註解 無‧
|
P.D.
版主 發表:603 回覆:4038 積分:3874 註冊:2006-10-31 發送簡訊給我 |
|
gxxc2008
一般會員 發表:4 回覆:4 積分:1 註冊:2008-06-13 發送簡訊給我 |
|
delphihelp
一般會員 發表:1 回覆:1 積分:0 註冊:2008-07-08 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |