⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 很多 delphi 精彩小例子。供大家参考。
💻 ~PAS
字号:
unit Unit1; 
interface 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  StdCtrls; 
type 
  TForm1 = class(TForm) 
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject); 
  private 
  public 
    { Public declarations } 
  end; 
type 
  TMyListBox=class(TListBox) 
  private 
    procedure WndProc(var Message: TMessage); override; 
 //覆盖WndProc函数,处理发送到控件的消息
  end; 
var
  Form1: TForm1; 
  M:TMyListBox; 
  p:TPoint; 
implementation 
{$R *.DFM} 
procedure TForm1.FormCreate(Sender: TObject); 
var 
   i:integer; 
begin 
  p.x:=0; 
  p.y:=0; 
  M:=TMyListBox.Create(Form1); //生成ListBox对象
  M.Parent:=Form1;//设置ListBox控件所在的父对象
  M.Left:=5;//设置ListBox的位置
  M.Top:=30;
  M.Width:=150;//设置ListBox的大小
  M.Height:=120;
  M.Font.Size:=16; //设置ListBox显示的文字的大小
  M.Font.Style:=[fsBold,fsItalic]; //设置文字风格
  for i:=0 to 200 do
  //该循环向ListBox中添加文字
  begin 
    M.Items.Add(inttostr(i)); 
  end; 
end; 
{ TMyListBox }
procedure TMyListBox.WndProc(var Message: TMessage);
//响应用户单击滚动条的事件,进行处理
begin 
  if (Message.Msg=WM_VSCROLL) and (Message.WParamLo=SB_ENDSCROLL) then 
  begin 
    Form1.Label1.Caption:=inttostr(ItemAtPos(p,true)); 
    inherited; 
  end 
  else 
    inherited; 
end; 
end. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -