To TuroLog:
Nudil jsem se, tak můžeš zkusit tohle:
1) Plácni na formulář RichEdit a ComboBox
2) Vlož kód
3) Nastav ComboBoxu property Style na csOwnerDrawFixed
4) Prirad mu jendotlive Eventy(OnChange a OnDrawItem)
5) U RichEditu nastva Eventu OnClick a OnKeyDown
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ComboBox1Change(Sender: TObject);
procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items := Screen.Fonts;
end;
procedure SetActiveText(Combo: TCustomComboBox; const FontName: string);
var ind : Integer;
begin
Assert(Combo <> NIL);
ind := Combo.Items.IndexOf(FontName);
if(ind = -1) then exit; // not found
Combo.ItemIndex := ind;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var c: TComboBox;
begin
c := TComboBox(Control);
c.Brush.Color := clWhite;
c.Canvas.FillRect(Rect);
c.Canvas.Font.Name := c.Items[Index];
c.Canvas.Font.Size := 12;
Windows.DrawText(c.Canvas.Handle, PChar(c.Items[Index]), Length(c.Items[Index]), Rect, DT_CENTER);
end;
procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SetActiveText(ComboBox1,RichEdit1.SelAttributes.Name);
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
RichEdit1.SelAttributes.Name := ComboBox1.Items[ComboBox1.ItemIndex];
RichEdit1.SetFocus;
end;
procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if(Key in [VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT,VK_HOME,VK_END]) then
SetActiveText(ComboBox1, RichEdit1.SelAttributes.Name);
end;
end.