Created
February 3, 2015 03:40
-
-
Save auycro/03799b6129d80774b287 to your computer and use it in GitHub Desktop.
DrawMultipleLine in TStringGrid Delphi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//グリッドのセルを作成 | |
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; | |
Rect: TRect; State: TGridDrawState); | |
begin | |
if Pos(#13#10, StringGrid1.Cells[ACol, ARow]) > 0 then | |
begin | |
StringGrid1.Canvas.FillRect(Rect); | |
Inc(Rect.Left, 2); | |
Inc(Rect.Top, 2); | |
DrawText(StringGrid1.Canvas.Handle, PChar(StringGrid1.Cells[ACol, ARow]), -1, Rect, DT_NOPREFIX or DT_WORDBREAK); | |
//OutputDebugString(PChar(StringGrid1.Cells[ACol, ARow])); | |
end; | |
end; | |
//セルの高さ更新 | |
procedure TForm1.UpdateRowHeights(AGrid: TStringGrid); | |
var | |
Y: Integer; | |
MaxHeight: Integer; | |
X: Integer; | |
R: TRect; | |
TxtHeight: Integer; | |
begin | |
for Y := AGrid.FixedRows to AGrid.RowCount - 1 do | |
begin | |
MaxHeight := AGrid.DefaultRowHeight - 4; | |
for X := AGrid.FixedCols to AGrid.ColCount - 1 do | |
begin | |
R := Rect(0, 0, AGrid.ColWidths[X] - 4, 0); | |
TxtHeight := DrawText(AGrid.Canvas.Handle, PChar(AGrid.Cells[X, Y]), -1, | |
R, DT_WORDBREAK or DT_CALCRECT); | |
if TxtHeight > MaxHeight then | |
MaxHeight := TxtHeight; | |
end; | |
AGrid.RowHeights[Y] := MaxHeight + 4; | |
end; | |
end; | |
//グリッドを再作成 | |
procedure TForm1.RefreshStringGrid; | |
begin | |
UpdateRowHeights(StringGrid1); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment