Показать сообщение отдельно
  #4  
Старый 30.12.2009, 11:55
mifka72 mifka72 вне форума
Прохожий
 
Регистрация: 14.12.2009
Сообщения: 4
Репутация: 10
Сообщение

кому интересно, всё выглядит так
Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ShellCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    ColorBox1: TColorBox;
    ListBox2: TListBox;
    RichEdit1: TRichEdit;
    procedure ListBox1Click(Sender: TObject);
    procedure ColorBox1Select(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox1Click(Sender: TObject);
  function AddColorText(Text: String; Color: TColor): String;
  begin
    RichEdit1.SelAttributes.Color := Color;
    RichEdit1.SelText := Text;
    RichEdit1.SelAttributes.Color := clBlack;
  end;
var
i:Integer;
c:String;
begin
if ListBox2.ItemIndex=-1 then
 begin
 if ListBox2.Items.Count=0 then
  begin
  ListBox2.Items.Append(ColorToString(ColorBox1.Selected));
  ListBox2.ItemIndex:=0;
  end
 else
  begin
  ListBox2.ItemIndex:=0;
  end;
 end;
i:=ListBox2.ItemIndex;
c:=ListBox2.Items[i];
i:=ListBox1.ItemIndex;
RichEdit1.Lines.Add(AddColorText(ListBox1.Items[i],StringToColor(c)));
end;

procedure TForm1.ColorBox1Select(Sender: TObject);
begin
ListBox2.Items.Append(ColorToString(ColorBox1.Selected));
ListBox2.ItemIndex:=ListBox2.Items.Count-1;
end;

end.
+ параметры
Код:
object Form1: TForm1
  Left = 190
  Top = 101
  Width = 354
  Height = 180
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ListBox1: TListBox
    Left = 112
    Top = 0
    Width = 105
    Height = 153
    ItemHeight = 13
    Items.Strings = (
      'one'
      'two'
      'free'
      'four'
      'five'
      'six'
      'seven'
      'eight'
      'nine')
    TabOrder = 0
    OnClick = ListBox1Click
  end
  object ColorBox1: TColorBox
    Left = 224
    Top = 0
    Width = 121
    Height = 22
    ItemHeight = 16
    TabOrder = 1
    OnSelect = ColorBox1Select
  end
  object ListBox2: TListBox
    Left = 224
    Top = 24
    Width = 121
    Height = 129
    ItemHeight = 13
    TabOrder = 2
  end
  object RichEdit1: TRichEdit
    Left = 0
    Top = 0
    Width = 105
    Height = 153
    TabStop = False
    ReadOnly = True
    ScrollBars = ssVertical
    TabOrder = 3
  end
end
Работает так: выбираем цвет и жмём на текст в среднем поле, получается цветная строка в первом(левом) поле
Ответить с цитированием