Однако, заменив процедуры столкнулся с проблемой, что строчки не всегда две, да и символом ";" делить строки не удобно, тем более, набор строк уже есть. Решил воспользоваться такой удивительной вещью как Strings, которая за сама и на строки поделит и даже их количество посчитает. Получилось как-то так, короче и универсальнее:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState); var Line1: string; Line2: string; ptr: integer; padding: integer; hGrid: TStringGrid; begin hGrid := (Sender as TStringGrid); ptr := Pos(';', hGrid.Cells[Col, Row]); if ptr > 0 then begin Line1 := Copy(hGrid.Cells[Col, Row], 1, ptr - 1); Line2 := Copy(hGrid.Cells[Col, Row], ptr + 1, Length(hGrid1.Cells[Col, Row]) - ptr); end else Line1 := hGrid.Cells[Col, Row]; hGrid.Canvas.FillRect(Rect); hGrid.Canvas.TextOut(Rect.Left, Rect.Top + 2, Line1); if ptr > 0 then hGrid.Canvas.TextOut(Rect.Left, Rect.Top - hGrid.Canvas.Font.Height + 3, Line2); end;
procedure TForm1.GridDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
hGrid: TStringGrid;
Str:Tstrings;
i:integer;
begin
hGrid := (Sender as TStringGrid);
Str:=Tstringlist.Create;
Str.Text:=Hgrid.Cells[ACol,Arow];
hGrid.Canvas.FillRect(Rect);
for i:=0 to str.count-1 do
begin
hGrid.Canvas.TextOut(Rect.Left, Rect.Top -
(hGrid.Canvas.Font.Height-3)*i , str[i]);
end;
str.free;
end;
P.S. А на ресурсе оказывается еще способ короче и вроде-как современнее, но я до него не дочитал.
Комментариев нет:
Отправить комментарий