Главная Новые темы Список тем Задать вопрос Поиск  

Форум "Delphi"


Паскаль, Делфи


 #0 Zdvitas © 20.06.07 13:46:38 - 16.07.07 23:49:12

Форматирвание текста



Как в делфи сделать так чтобы допустим в компоненте memo или в каком нибудь другом разлоные кусочки текста были разным форматированием(размер шрифт итп)?
Заранее благодарен=) Цитата

 #1 Паша © 20.06.07 13:59:47

компонент TRichEdit
 #2 Zdvitas © 20.06.07 14:23:35

ну допутим у меня есть текст

Предварительный просмотр (пока тестируется, возможно, не всегда работает правильно)

кторый вводиться с клавиатуры как сделать так чтобы "Предварительный просмотр" было жирным... или любым другим... Заранее спасибо=)
 #3 Deep © 20.06.07 15:47:42

смотри демку
"C:\Program Files\Borland\delphi7\Demos\RichEdit\&q­uot;

файлик remain.pas


>  как сделать так чтобы "Предварительный просмотр" было жирным...

procedure TMainForm.BoldButtonClick(Sender: TObject);
begin
  if FUpdating then Exit;
  if BoldButton.Down then
    CurrText.Style := CurrText.Style + [fsBold]
  else
    CurrText.Style := CurrText.Style - [fsBold];
end;


 #4 Паша © 20.06.07 17:47:15

>  "Предварительный просмотр"

у чего? у компонета "мемо"? или чего? вопрос непонятен
 #5 Zdvitas © 20.06.07 21:06:21

Спасибо=)
 #6 Zdvitas © 22.06.07 00:20:04

>#3 Deep ©


 это если он у меня выделен в richEdit а если я просто знаю этот текст но мне нужно его изменить програмно...
 #7 Deep © 22.06.07 11:17:52

> это если он у меня выделен в richEdit
если не выделен, то тебе либо надо задавать атрибуты текста перед его записью в RichEdit или текст нужно выделить программно (SelStart, SelLength) и задать ему атрибуты (SelAttributes).

пример 1.

procedure TForm1.Button1Click(Sender: TObject);

begin
  with RichEdit1.SelAttributes do
  begin
    Color := clRed;
    Height := Height + 5;
  end;
  RichEdit1.Lines.Add('This line of text will be red.');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  RichEdit1.DefAttributes.Color := clBlue;
  RichEdit1.DefAttributes.Style := [fsBold, fsItalic];
end;



пример 2

This example requires a TRichEdit, a TButton, and a TFindDialog.
Clicking the button click will display a Find Dialog to the right of the edit control.  Filling in the "Find what" text and pressing the Find Next button will select the first matching string in the Rich Edit control that follows the previous selection.

procedure TForm1.Button1Click(Sender: TObject);

begin
  FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
  FindDialog1.Execute;
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
begin
  with RichEdit1 do
  begin
    { begin the search after the current selection if there is one }
    { otherwise, begin at the start of the text }
    if SelLength <> 0 then

      StartPos := SelStart + SelLength
    else

      StartPos := 0;

    { ToEnd is the length from StartPos to the end of the text in the rich edit control }

    ToEnd := Length(Text) - StartPos;

    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
    end;
  end;
end;



Ключевые свойства  SelStart, SelLength, SelAttributes
 #8 Zdvitas © 16.07.07 23:49:12

Спасибо=)




  • Написать ответ

    Имя: Регистрация HTML?
    smiles смайлики
    Потом перейти в:    
    паутина



      ©  webest.net, 2002-2007  

    top.mail.ru
    » Бесплатный счетчик посещений
    » Рейтинг сайтов