怎样做控件?? Delphi控件源码就是最好的示例了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你一个例子,一个具备URL的Label控件:unit SWURLLabel;interfaceuses Windows, Classes, Controls, StdCtrls, SysUtils, Forms, Graphics, ShellAPI;type TSWURLLabel = class(TLabel) // 从TLabel类派生 private FOnBeforeExecuteURL: TNotifyEvent; // 指向执行URL之前要调用的过程 FURL: String; // URL字符串 procedure SetURL(Value:String); protected procedure Click; override; // 重载TLabel的Click方法 public constructor Create(AOwner:TComponent); override; // 构造函数 function ExecuteURL: Boolean; // 方法,执行URL published property OnBeforeExecuteURL: TNotifyEvent read FOnBeforeExecuteURL write FOnBeforeExecuteURL default nil; property OnExecuteURL: TNotifyEvent read FOnExecuteURL write FOnExecuteURL default nil; property URL:String read FURL write SetURL; end;procedure Register;implementationconst DefaultURL:String = 'http://seawave.yeah.net';{ 重载TLabel的Click方法 }procedure TSWURLLabel.Click;begin inherited Click; // 执行TLabel的Click过程 ExecuteURL; // 调用ExecuteURL过程来执行URLend;{ 构造函数,初始化属性 }constructor TSWURLLabel.Create(AOwner:TComponent);begin inherited Create(AOwner); // 首先调用父类的构造函数 FURL := DefaultURL; // URL属性值初始化为默认值 Caption := DefaultURL; // Caption Font.Color := clBlue; // 颜色默认为蓝色 Font.Style := [fsUnderline]; // 字体默认为带下划线 Cursor := crHandPoint; // 光标形状默认为手掌形end;{ 方法,调用Windows API执行URL }function TSWURLLabel.ExecuteURL;var ZFileName:array[0..255] of char;begin if Assigned(FOnBeforeExecuteURL) then FOnBeforeExecuteURL(Self); // 若指定了事件处理过程则调用它 if Length(FURL)>0 then begin // 当URL不为空时执行 StrPCopy(ZFileName, FURL); ShellExecute(Application.Handle, nil, ZFileName, nil, nil, SW_SHOWNORMAL); end;end;{ 登记新构件的过程 }procedure Register;begin // 第一个参数是面板页的名字,第二个参数是新构件的类名 RegisterComponents('SeaWave', [TSWURLLabel]);end;{ 私有方法,设置URL属性值 }procedure TSWURLLabel.SetURL(Value:String);begin FURL := Value; if csDesigning in ComponentState then Caption := Value;end;end. 在DELPHI5中有自己的例子,介绍如何做.而且在很多书中也很详细 只有直接编写源代码一种方法吗?有没有什么可视化的方法,事实上我只是想把一个常用的小的模块作为一个整体,涉及到DBGird,Tedit.Tbutton,又没有什么简单的实现方法?? 一本<<Component Write Guide>>上次我下了,还可以吧 一本<<Component Write Guide>>上次我下了,还可以吧 怎么让自定义类型对单元外是不可见的 请问通过网络如何来发消息啊? 寻求把excel窗口放到delphi表单的面板上的方法. 一个关于treeview的问题 SQL中的日期问题. 请问高手WebSnap的问题? 怎样删除菜单条目 不知不觉,我也四颗了 祝福者有分! 当点击dbgrid的任一列的标题时,怎样才能得到该列的字段名。 如何用delphi写VPN连接程序啊! 难题,可以进来看一下,谢谢各位大侠! (100分)谁知道那里有 Xaudio sdk 3.2.9 下载?
unit SWURLLabel;interfaceuses
Windows, Classes, Controls, StdCtrls, SysUtils, Forms,
Graphics, ShellAPI;type
TSWURLLabel = class(TLabel) // 从TLabel类派生
private
FOnBeforeExecuteURL: TNotifyEvent; // 指向执行URL之前要调用的过程 FURL: String; // URL字符串
procedure SetURL(Value:String);
protected
procedure Click; override; // 重载TLabel的Click方法
public
constructor Create(AOwner:TComponent); override; // 构造函数
function ExecuteURL: Boolean; // 方法,执行URL
published
property OnBeforeExecuteURL: TNotifyEvent
read FOnBeforeExecuteURL
write FOnBeforeExecuteURL default nil;
property OnExecuteURL: TNotifyEvent
read FOnExecuteURL
write FOnExecuteURL default nil; property URL:String read FURL write SetURL;
end;procedure Register;implementationconst DefaultURL:String = 'http://seawave.yeah.net';{ 重载TLabel的Click方法 }
procedure TSWURLLabel.Click;
begin
inherited Click; // 执行TLabel的Click过程
ExecuteURL; // 调用ExecuteURL过程来执行URL
end;{ 构造函数,初始化属性 }
constructor TSWURLLabel.Create(AOwner:TComponent);
begin
inherited Create(AOwner); // 首先调用父类的构造函数
FURL := DefaultURL; // URL属性值初始化为默认值
Caption := DefaultURL; // Caption
Font.Color := clBlue; // 颜色默认为蓝色 Font.Style := [fsUnderline]; // 字体默认为带下划线
Cursor := crHandPoint; // 光标形状默认为手掌形
end;{ 方法,调用Windows API执行URL }
function TSWURLLabel.ExecuteURL;
var
ZFileName:array[0..255] of char;
begin
if Assigned(FOnBeforeExecuteURL) then
FOnBeforeExecuteURL(Self); // 若指定了事件处理过程则调用它
if Length(FURL)>0 then begin
// 当URL不为空时执行
StrPCopy(ZFileName, FURL);
ShellExecute(Application.Handle, nil,
ZFileName, nil, nil, SW_SHOWNORMAL); end;end;
{ 登记新构件的过程 }
procedure Register;
begin
// 第一个参数是面板页的名字,第二个参数是新构件的类名
RegisterComponents('SeaWave', [TSWURLLabel]);
end;{ 私有方法,设置URL属性值 }
procedure TSWURLLabel.SetURL(Value:String);
begin
FURL := Value;
if csDesigning in ComponentState then
Caption := Value;
end;end.