|
功能:在标签上显示URL网址,点击标签,则跳转到相应的网址。
代码简单,直接贴上来:
- unit URLlabel;
-
- {$mode objfpc}{$H+}
-
- interface
-
- uses
- Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,Windows,ShellAPI;
-
- type
- TURLlabel = class(TCustomLabel)
- private
- { Private declarations }
- fURL : String;
- procedure SetURL(value : string);
- protected
- { Protected declarations }
- public
- { Public declarations }
- constructor Create (AOwner : TComponent); override;
- procedure Click; override;
- published
- { Published declarations }
- Property URL : String Read fURL write setURL;
- Property Align;
- Property Alignment;
- Property AutoSize;
- Property caption;
- Property Color;
- Property Cursor;
- Property Font;
- Property ParentFont;
- end;
-
- procedure Register;
-
- implementation
-
- procedure TURLlabel.Click;
- begin
- ShellExecute(0, 'open', PChar(fURL), nil, nil, SW_SHOWNORMAL);
- inherited;
- end;
-
- procedure TURLlabel.SetURL(value : string);
- begin
- if fURL <> Value then
- begin
- Caption := Value;
- fURL := Value;
- end;
- end;
-
- constructor TURLlabel.Create(AOwner: TComponent);
- begin
- inherited ;
- Font.Color := clBlue;
- Font.Style := [fsUnderline];
- Cursor := crHandPoint;
-
- URL :='http://www.fpccn.com';
-
- end;
-
- procedure Register;
- begin
- {$I urllabel_icon.lrs}
- RegisterComponents('fpccn',[TURLlabel]);
- end;
-
- end.
复制代码 |
|