Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.ForeColor = vbGreen
Label1.Font.Bold = False
Label1.Font.Size = 10
Label1.Font.Underline = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Font.Italic = True 'Not Label1.Font.Italic
Label1.Font.Bold = False
Label1.ForeColor = vbGreen
Label1.Font.Size = 10
Label1.Font.Underline = False
End Sub调 Browse 参阅:
1.Start a new project in Visual Basic. Form1 is created by default. Add a Command button to Form1. Command1 is created by default. 2.Copy the following code into the Form's module: Private Const SW_SHOW = 5 ' Displays Window in its current size
' and position
Private Const SW_SHOWNORMAL = 1 ' Restores Window if Minimized or
' Maximized Private 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 Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long Private Sub Command1_Click()
Dim FileName, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer ' First, create a known, temporary HTML file
BrowserExec = Space(255)
FileName = "C:\temphtm.HTM"
FileNumber = FreeFile ' Get unused file number
Open FileName For Output As #FileNumber ' Create temp HTML file
Write #FileNumber, "<HTML> <\HTML>" ' Output text
Close #FileNumber ' Close file
' Then find the application associated with it
RetVal = FindExecutable(FileName, Dummy, BrowserExec)
BrowserExec = Trim(BrowserExec)
' If an application is found, launch it!
If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error
MsgBox "Could not find associated Browser", vbExclamation, _
"Browser Not Found"
Else
RetVal = ShellExecute(Me.hwnd, "open", BrowserExec, _
"www.microsoft.com", Dummy, SW_SHOWNORMAL)
If RetVal <= 32 Then ' Error
MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
End If
End If
Kill FileName ' delete temp HTML file
End Sub3.Press the F5 key to run the project. Click on Command1 and your default Internet Browser will start.
Label1.ForeColor = vbGreen
Label1.Font.Bold = False
Label1.Font.Size = 10
Label1.Font.Underline = False
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.Font.Italic = True 'Not Label1.Font.Italic
Label1.Font.Bold = False
Label1.ForeColor = vbGreen
Label1.Font.Size = 10
Label1.Font.Underline = False
End Sub调 Browse 参阅:
1.Start a new project in Visual Basic. Form1 is created by default. Add a Command button to Form1. Command1 is created by default. 2.Copy the following code into the Form's module: Private Const SW_SHOW = 5 ' Displays Window in its current size
' and position
Private Const SW_SHOWNORMAL = 1 ' Restores Window if Minimized or
' Maximized Private 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 Private Declare Function FindExecutable Lib "shell32.dll" Alias _
"FindExecutableA" (ByVal lpFile As String, ByVal lpDirectory As _
String, ByVal lpResult As String) As Long Private Sub Command1_Click()
Dim FileName, Dummy As String
Dim BrowserExec As String * 255
Dim RetVal As Long
Dim FileNumber As Integer ' First, create a known, temporary HTML file
BrowserExec = Space(255)
FileName = "C:\temphtm.HTM"
FileNumber = FreeFile ' Get unused file number
Open FileName For Output As #FileNumber ' Create temp HTML file
Write #FileNumber, "<HTML> <\HTML>" ' Output text
Close #FileNumber ' Close file
' Then find the application associated with it
RetVal = FindExecutable(FileName, Dummy, BrowserExec)
BrowserExec = Trim(BrowserExec)
' If an application is found, launch it!
If RetVal <= 32 Or IsEmpty(BrowserExec) Then ' Error
MsgBox "Could not find associated Browser", vbExclamation, _
"Browser Not Found"
Else
RetVal = ShellExecute(Me.hwnd, "open", BrowserExec, _
"www.microsoft.com", Dummy, SW_SHOWNORMAL)
If RetVal <= 32 Then ' Error
MsgBox "Web Page not Opened", vbExclamation, "URL Failed"
End If
End If
Kill FileName ' delete temp HTML file
End Sub3.Press the F5 key to run the project. Click on Command1 and your default Internet Browser will start.
看懂下面例子:
' 标题: 在VB中捕捉MouseLeave事件
' 作者: James Guo
' 您可以自由地在您的应用程序应用该代码,无需征得作者的同意.
' 欢迎光临VB天堂, 一个VB程序员的VB主页.
' 地址: http://www.zhanjiang.gd.cn/personal/jamgsguo
' Email: [email protected] Explicit
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As LongPrivate Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
' 没有使用MouseLeave事件,当鼠标快速移动时,程序来不及响应
StatusBar1.Panels(1).Text = "This is Command1"
End SubPrivate Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim MouseOver As Boolean
'判断当前鼠标位置是否在Command2上
MouseOver = (0 <= X) And (X <= Command2.Width) And (0 <= Y) And (Y <= Command2.Height)
If MouseOver Then
' MouseOver Event
' 假如鼠标在Command2上, 则利用SetCapture将每一个鼠标事件都传递给Command2
' 并在StatusBar1.Panels(1)上显示帮助信息
StatusBar1.Panels(1).Text = "This is Command2"
SetCapture Command2.hWnd
Else
' MouseLeave Event
' 假如鼠标不在Command2上, 则利用SetCapture释放鼠标捕捉
' 并清除在StatusBar1.Panels(1)上的帮助信息
StatusBar1.Panels(1).Text = ""
ReleaseCapture
End If
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
StatusBar1.Panels(1).Text = ""
End Sub