怎样实现与网站的链接?

yang_xz 2001-12-06 09:22:51
怎样实现在Form上放一Label,输入网址,程序运行时单击该网址就链接到网站?就象Delphi5的Help中的About上的一样?
...全文
46 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
王集鹄 2001-12-06
  • 打赏
  • 举报
回复
//pas
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
procedure Label2MouseEnter(Sender: TObject);
procedure Label2MouseLeave(Sender: TObject);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

uses
ShellApi;

procedure TForm1.Label2MouseEnter(Sender: TObject);
begin
TLabel(Sender).Font.Color := clBlue;
TLabel(Sender).Font.Style := [fsUnderline];
end;

procedure TForm1.Label2MouseLeave(Sender: TObject);
begin
TLabel(Sender).Font.Color := clWindowText;
TLabel(Sender).Font.Style := [];
end;

procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ShellExecute(0, 'OPEN', PChar(TLabel(Sender).Caption), nil, nil, SW_NORMAL);
end;

end.

//dfm
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 8
Top = 48
Width = 99
Height = 13
Caption = 'http://www.csdn.net'
OnMouseDown = Label1MouseDown
OnMouseEnter = Label2MouseEnter
OnMouseLeave = Label2MouseLeave
end
object Label2: TLabel
Left = 8
Top = 104
Width = 104
Height = 13
Caption = 'http://www.sohu.com'
OnMouseDown = Label1MouseDown
OnMouseEnter = Label2MouseEnter
OnMouseLeave = Label2MouseLeave
end
end

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧