![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
|
|
#1
|
|||
|
|||
|
Добрый день. Я начну.
Необходимо сделать список шрифтов в виде самих шрифтов. Вот в нете нашел такой вот код: Код:
unit Fontlist;
interface
uses
Windows, Classes, Graphics, Forms, Controls, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
FontLabel: TLabel;
procedure FormCreate(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
procedure DrawItem(Control: TWinControl; index: Integer; Rect: TRect;
State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; index: Integer;
var Height: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Listbox1.Items := Screen.Fonts;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
FontLabel.Caption := ListBox1.Items[ListBox1.ItemIndex];
end;
procedure TForm1.DrawItem(Control: TWinControl; index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
FillRect(Rect);
Font.name := ListBox1.Items[index];
Font.Size := 0; // use font's preferred size
TextOut(Rect.Left+1, Rect.Top+1, ListBox1.Items[index]);
end;
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; index: Integer;
var Height: Integer);
begin
with ListBox1.Canvas do
begin
Font.name := Listbox1.Items[index];
Font.Size := 0; // use font's preferred size
Height := TextHeight('Wg') + 2; // measure ascenders and descenders
end;
end;
end.Но как бы он не работает... Иии тут Listbox я вообще делаю через ComboBox но и так и так вообще не выходит... Иии тут написано процедура TForm1.DrawItem но такой нет она же только или в ListBox или в ComboBox на Form её нет...я делал через TForm1.ListBox1DrawItem но всё равно результат нулевой... Помогите кто чем может) |
|
#2
|
|||
|
|||
|
Кстати в этом коде лишний Label походу...и вообще я сделал для Richedit это всё...но важен мне сам список ибо всю остальную функцию я выполнил...
|
|
#3
|
||||
|
||||
|
так надо??
|
|
#4
|
||||
|
||||
|
вот еще с комбиком:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1Click(Sender: TObject);
procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ListBox1.Items.Assign(Screen.Fonts);
ComboBox1.Items.Assign(Screen.Fonts);
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
with ListBox1.Canvas do
begin
Font.Name:=ListBox1.Items[Index];
Font.Size:=0;
Height:=TextHeight('Wg')+2;
end;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
FillRect(Rect);
Font.Name:=ListBox1.Items[Index];
Font.Size:=0;
TextOut(Rect.Left, Rect.Top, ListBox1.Items[Index]);
end;
end;
procedure TForm1.ListBox1Click(Sender: TObject);
begin
Label1.Caption:=ListBox1.Items[ListBox1.ItemIndex];
end;
procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
if Index=-1 then Exit;
with ComboBox1.Canvas do
begin
Font.Name:=ComboBox1.Items[Index];
Font.Size:=0;
Height:=TextHeight('Wg')+2;
end;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
if Index=-1 then Exit;
with ComboBox1.Canvas do
begin
FillRect(Rect);
Font.Name:=ComboBox1.Items[Index];
Font.Size:=0;
TextOut(Rect.Left, Rect.Top, ComboBox1.Items[Index]);
end;
end;
end. |
|
#5
|
|||
|
|||
|
В ComboBox надо было в Style поставить csOwnerDrawVariable
-_-" Спасибо NumLockу сверил его архив смоим) |
|
#6
|
|||
|
|||
|
Блин вот теперь когда это заработало теперь вот нне работает определение шрифта: когда щёлкаешь на отдельную область текста в ричедите что бы он показыавл что там за шриф в этом же комбобоксе ну как в ворде...
У меня раньше тупо так работало в MouseUpе: ComboBox2.SelText:=RichEdit1.SelAttributes.Name; Хотя размер отлично показыввыает: ComboBox1.Text:=IntToStr(RichEdit1.SelAttributes.s ize); |