Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2007.06.17;
Скачать: [xml.tar.bz2];

Вниз

Несколько строк текста в одной ячейке StringGrid   Найти похожие ветки 

 
Alex7 ©   (2007-05-22 14:12) [0]

Здравствуйте, уважаемые мастера.
Подскажите, пожалуйста, как программно внести текст в одну ячеку StringGrid, несколькими строками. Нужно примерно так, как это делается при заполнении мемо-поля: Add добавляет текст как следующую строку мемо-поля. Спасибо.


 
Думкин ©   (2007-05-22 14:23) [1]

http://www.delphimaster.ru/articles/stringgrid/index.html


 
Думкин ©   (2007-05-22 14:23) [2]

Или речь о переносах автоматом?


 
Alex7 ©   (2007-05-23 06:26) [3]

Речь идет о принудительных переносах вне зависимости от длины предыдущей строки.
Спасибо за ссылку.


 
Alex7 ©   (2007-05-23 08:28) [4]

Видимо нужно вставить какой-то служебный символ в текст s:string, которая отрисовывается с помощью:
DrawText(StringGrid1.Canvas.Handle,PChar(s),length(s),Rect,DT_WORDBREAK)
Хотя для принудительного переноса DT_WORDBREAK, наверно, можно не указывать.
Уточняющий вопрос:
Каким символом нужно поделить текст s:string для принудительного переноса на следующую строку  в той же ячейке StringGrid?
В  http://www.delphimaster.ru/articles/stringgrid/index.html ответа на этот вопрос не нашел.
Спасибо.


 
Loginov Dmitry ©   (2007-05-23 09:44) [5]

Используй в качестве редактора текста ячейки обычный TMemo.


 
Alex7 ©   (2007-05-23 11:07) [6]

Уточните, пожалуйста.
with MyStringGrid.Cells[0,0] as TMemo do ...;
не принимается.


 
Loginov Dmitry ©   (2007-05-23 11:28) [7]

> with MyStringGrid.Cells[0,0] as TMemo do


Класс!


 
Loginov Dmitry ©   (2007-05-23 12:49) [8]

unit Unit2;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, Grids, Math;

type
 TFrame2 = class(TFrame)
   StringGrid1: TStringGrid;
   Memo1: TMemo;
   procedure Memo1Exit(Sender: TObject);
   procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
     Rect: TRect; State: TGridDrawState);
   procedure StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
     var Value: String);
   procedure Memo1Change(Sender: TObject);
 private
   { Private declarations }
   CurrectCellHeight: Integer;
 public
   { Public declarations }
 end;

implementation

{$R *.dfm}

procedure TFrame2.Memo1Exit(Sender: TObject);
begin
 with StringGrid1 do
 begin
   Memo1.Visible := False;
   StringGrid1.Cells[Col, Row] := Memo1.Text;          
 end;
end;

procedure TFrame2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
var
 AText: string;
begin
 with StringGrid1, StringGrid1.Canvas do
 begin
   if (ACol > FixedCols - 1) and (ARow > FixedRows - 1) then
   begin
     FillRect(Rect);
     AText := StringGrid1.Cells[ACol, ARow];
     if AText <> "" then
     begin
       DrawText(Handle, PChar(AText), -1, Rect, DT_CALCRECT or DT_WORDBREAK);
       if RowHeights[ARow] < Rect.Bottom - Rect.Top then
         RowHeights[ARow] := Rect.Bottom - Rect.Top;
       DrawText(Handle, PChar(AText), -1, Rect, DT_WORDBREAK);
     end;
   end;
 end;
end;

procedure TFrame2.StringGrid1GetEditText(Sender: TObject; ACol,
 ARow: Integer; var Value: String);
var
 ARect: TRect;
 SymbHeight: Integer;
begin
 SymbHeight := StringGrid1.Canvas.TextHeight("0");
 CurrectCellHeight := StringGrid1.RowHeights[ARow] + SymbHeight;
 ARect := StringGrid1.CellRect(ACol, ARow);
 ARect.TopLeft := ScreenToClient(StringGrid1.ClientToScreen(ARect.TopLeft));
 ARect.BottomRight := ScreenToClient(StringGrid1.ClientToScreen(ARect.BottomRight));
 ARect.Bottom := ARect.Bottom + SymbHeight;
 ARect.Right := ARect.Right + StringGrid1.Canvas.TextWidth("0");

 with Memo1 do
 begin
   BoundsRect := ARect;
   Clear;
   Text := StringGrid1.Cells[ACol, ARow];
   Visible := True;
   BringToFront;
   SetFocus;
 end;
end;

procedure TFrame2.Memo1Change(Sender: TObject);
var
 NewHeight: Integer;
begin
 NewHeight := (Memo1.Lines.Count + 1) * StringGrid1.Canvas.TextHeight("0");
 Memo1.Height := Max(NewHeight, CurrectCellHeight);
end;

end.


 
Alex7 ©   (2007-05-23 13:32) [9]

>Loginov Dmitry
Спасибо за подробный ответ.



Страницы: 1 вся ветка

Форум: "Начинающим";
Текущий архив: 2007.06.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.04 c
2-1180086751
Юра
2007-05-25 13:52
2007.06.17
Ассоциация файлов!


15-1179583409
PHPdeveloper
2007-05-19 18:03
2007.06.17
Каталог статей, PHP


2-1180344944
Infinityx93
2007-05-28 13:35
2007.06.17
CASE


15-1179845192
Strate
2007-05-22 18:46
2007.06.17
Перевод из Fortran в Pascal (Delphi)


2-1180348039
Чип
2007-05-28 14:27
2007.06.17
Фильтрация через компонент table (по 1 значению)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский