Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  4 625

•  TDictionary Custom Sort  6 627

•  Fast Watermark Sources  6 405

•  3D Designer  9 351

•  Sik Screen Capture  6 738

•  Patch Maker  7 124

•  Айболит (remote control)  7 131

•  ListBox Drag & Drop  5 989

•  Доска для игры Реверси  97 568

•  Графические эффекты  7 323

•  Рисование по маске  6 611

•  Перетаскивание изображений  5 483

•  Canvas Drawing  5 859

•  Рисование Луны  5 581

•  Поворот изображения  5 092

•  Рисование стержней  3 658

•  Paint on Shape  2 891

•  Генератор кроссвордов  3 789

•  Головоломка Paletto  3 042

•  Теорема Монжа об окружностях  3 855

•  Пазл Numbrix  2 536

•  Заборы и коммивояжеры  3 248

•  Игра HIP  2 215

•  Игра Go (Го)  2 148

•  Симулятор лифта  2 527

•  Программа укладки плитки  2 168

•  Генератор лабиринта  2 664

•  Проверка числового ввода  2 319

•  HEX View  2 652

•  Физический маятник  2 283

 
скрыть

Текст в ячейке StringGrid если не помещается переносится на следующую ячейку



Сначала нужно обработать событие OnDrawCell компонента TStringGrid:


procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
  i, x, y: Integer;
begin
  if gdFixed in State then
    Exit;
  if ARow > 1 then
    Exit;
  {Draw row 1 with text from cell 1,1 spanning all cells in the row}
  with sender as TStringGrid do
  begin
    {Extend rect to include grid line on right, if not last cell in row}
    if aCol < Pred(ColCount) then
      Rect.Right := Rect.Right + GridlineWidth;
    {Figure out where the text of the first cell would start
    relative to the current cells rect}
    y := Rect.Top + 2;
    x := Rect.Left + 2;
    for i:= 1 to aCol - 1 do
      x := x - ColWidths[i] - GridlineWidth;
    {Paint cell pale yellow}
    Canvas.Brush.Color := $7FFFFF;
    Canvas.Brush.Style := bsSolid;
    Canvas.FillRect( Rect );
    {Paint text of cell 1,1 clipped to current cell}
    Canvas.TextRect( Rect, x, y, Cells[1, 1] );
  end;
end;

По созданию окна изобразим следующее


procedure TForm1.FormCreate(Sender: TObject);
var
  i, k: Integer;
begin
  with StringGrid1 do
  begin
    cells[1, 1] := 'A rather long line which will span cells';
    for i:= 1 to colcount-1 do
      for k:= 2 to rowcount -1 do
        cells[i,k] := Format( 'Cell[%d, %d]', [i, k]);
  end;
end;