はじめまして、宜しくお願いします。
TStringGridにおいてセルの結合をしたいと考えています。
過去ログを参考に以下のように作成しましたが
結合したセルの隣のセルの色が変わってしまったり、
セルの境界線がずれたりします。
5列目までで
1行目と2行目がFixedの時セルが結合されるというものです。
(DrawCellプロシージャーで)
with TStringGrid(Sender) do begin
DefaultDrawing := True;
if ((ACol < 6) and (gdFixed in State)) then begin
DefaultDrawing := False;
case ARow of
0 : Rect.Bottom := Rect.Bottom + RowHeights[1] - 1;
1 : Rect.Top := Rect.Top + RowHeights[0] - 1;
end;
Canvas.Brush.Color := clBtnFace;
Canvas.Font.Color := clBlack;
Canvas.FillRect(Rect);
DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end
else
begin
DefaultDrawing := True;
Canvas.FillRect(Rect);
DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end;
end;
ご教授お願いします。
また、この方法で駄目ならセル結合可能なコンポーネントも探そうかと考えています。
良いコンポーネントがありましたら教えてください。
範囲選択できないけど・・・
with TStringGrid(Sender) do begin
if ((ACol < 6) and (gdFixed in State) and (ARow < 2)) then begin
case ARow of
0 : Rect.Bottom := Rect.Bottom + RowHeights[1];
1 : Rect.Top := Rect.Top - (RowHeights[0] + 1);
end;
Canvas.Brush.Color := clBtnFace;
Canvas.Font.Color := clBlack;
Canvas.FillRect(Rect);
DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end else begin
Canvas.Font.Color := clBlack;
if gdFixed in State then begin
Canvas.Brush.Color := clBtnFace;
Canvas.FillRect(Rect);
DrawEdge(Canvas.Handle, Rect, BDR_RAISEDINNER, BF_RECT);
end else begin
Canvas.Brush.Color := clWindow;
Canvas.FillRect(Rect);
end;
DrawText(Canvas.Handle, PChar(Cells[ACol, ARow]), -1, Rect,
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end;
end;
あ、DefaultDrawing は 常に False で。
以下を最後に付けて下さい。
if gdFocused in State then
Canvas.DrawFocusRect(Rect);
deldelさん有り難う御座いました。
無事に解決いたしました。
またよろしくお願いします。
解決チェックを忘れました。
ツイート | ![]() |