我想在一个窗体的label上建立一个类似web的超级连接

宁城的雪 2003-12-06 05:45:57
我想在一个窗体的label上建立一个类似web的超级连接,当点击此Label时弹出一个新的窗体,而且当鼠标移到此label上颜色改变,离开又恢复。请各位帮忙。谢谢
...全文
45 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
WQ771211 2003-12-06
  • 打赏
  • 举报
回复
当鼠标移到此label上颜色改变,离开又恢复
---------------------------------------------
这种效果用label无法实现,如果鼠标移动太快,就不行
用一个有hWnd的控减(如textbox)
在mousemove时,调api函数SetCaptrue捕捉鼠标(全屏幕捕捉)
同样在该控件的mousemove中判断鼠标是否移出,如果移出,则ReleaseCaptrue
yanudd 2003-12-06
  • 打赏
  • 举报
回复
呵呵
他们该说的都说了!
祝你运行成功
goodname008 2003-12-06
  • 打赏
  • 举报
回复
' 打错了,这个有弹出新窗体的代码,要是想要链接到某个URL地址,就用ShellExecute函数

Option Explicit
Dim WithEvents lblURL As Label

Private Sub Form_Load()
Set lblURL = Controls.Add("VB.Label", "lblURL", Me)
With lblURL
.Caption = "http://www.163.com"
.AutoSize = True
.Top = 50 * 15
.Left = 100 * 15
.Visible = True
End With
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblURL.ForeColor = vbBlack
lblURL.FontUnderline = False
lblURL.MousePointer = vbDefault
End Sub

Private Sub lblURL_Click()
Dim frm As New Form1
frm.Show
End Sub

Private Sub lblURL_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblURL.ForeColor = vbBlue
lblURL.FontUnderline = True
lblURL.MousePointer = vbUpArrow
End Sub
goodname008 2003-12-06
  • 打赏
  • 举报
回复
忘写弹出新窗体的代码了,在lblURL_MouseMove里自己加吧。 :)
goodname008 2003-12-06
  • 打赏
  • 举报
回复

Option Explicit
Dim WithEvents lblURL As Label

Private Sub Form_Load()
Set lblURL = Controls.Add("VB.Label", "lblURL", Me)
With lblURL
.Caption = "http://www.163.com"
.AutoSize = True
.Top = 50 * 15
.Left = 100 * 15
.Visible = True
End With
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblURL.ForeColor = vbBlack
lblURL.FontUnderline = False
lblURL.MousePointer = vbDefault
End Sub

Private Sub lblURL_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
lblURL.ForeColor = vbBlue
lblURL.FontUnderline = True
lblURL.MousePointer = vbUpArrow
End Sub
3661512 2003-12-06
  • 打赏
  • 举报
回复
使用API函数ShellExcute
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As _
String, ByVal lpParameters As String, ByVal lpDirectory As String,_
ByVal nShowCmd As Long) As Long
在Label控件的click事件上加入代码:
Private Sub lblURL_Click()
Dim HyperJump
HyperJump = ShellExecute(0&, vbNullString, WEB, vbNullString,
vbNullString, vbNormalFocus)
其中WEB为你定义的超连接地址,例如:
Private Const WEB = "http://i.am/hellprisoner"
如果需要调入email,就要在email地址前加入mailto: 例如
Private Const WEB = "mailto:prisoner@990.net"
如果再在Label的属性中设置MousePointer = 99 'Custom 并把MouseIcon
设置为一只手的图标,当鼠标移动到标签上时,指针就变成手的形状,这就更
象超连接了。
- Prisoner
回答2:
可以先建立两个label控件label1和label2.设他们的caption分别为"我的mail"
和"我的主页"(或是其他你想要显示的内容).然后加入如下代码:
Private Sub Label1_Click()
Set ie = New InternetExplorer
ie.Visible = False
ie.Navigate "mailto:weiv@163.net"
End Sub

Private Sub Label2_Click()
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://playworld.126.com"
End Sub


7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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