📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Memo1: TMemo;
Button1: TButton;
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure Button1Click(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
var
lpstr:PChar;
c,h:integer;
tc:TRect;
begin
with Control as TListBox do
begin
c:=length(items[index]);
lpstr:=PChar(Items[index]);
tc:=clientrect;
h:=drawtext(Canvas.Handle,lpstr,c,tc,DT_CALCRECT or DT_WORDBREAK);
end;
Height:=h+4;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
listbox1.Items.Assign(memo1.Lines);
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
lpstr:PChar;
c:integer;
begin
with Control as TListBox do
begin
Canvas.FillRect(Rect);
c:=length(items[index]);
lpstr:=PChar(Items[index]);
drawtext(Canvas.Handle,lpstr,c,Rect,DT_WORDBREAK);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -