在窗体上画一个文本框、一个图片框和一个命令按钮。编写程序,使得当鼠标光标位于不同的控件或窗体上时,鼠标光标具有不同的形状,此时如果按下鼠标右键,则显示相应的信息。例如,当鼠标光标移到图片框上时,如果按下鼠标右键,则用一个信息框显示:“现在鼠标光标位于图片框中”。要求:在文本框和窗体上的鼠标光标使用系统提供的光标形状,而图片框和命令按钮上的鼠标光标使用自定义的形状。

    解:在窗体上_ 一个文本框、一个图片框和一个命令按钮,然后编写如下程序。
 
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        MsgBox "现在鼠标光标位于命令按钮框中", , "命令按钮"
    End If
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Command1.MousePointer = 99
    Command1.MouseIcon = LoadPicture("c:\1.ico")
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        MsgBox "现在鼠标光标位于窗体上", , "窗体"
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form1.MousePointer = 10
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        MsgBox "现在鼠标光标位于图片框中", , "命令按钮"
    End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Picture1.MousePointer = 99
    Command1.MouseIcon = LoadPicture("c:\2.ico")
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        MsgBox "现在鼠标光标位于文本框中", , "文本框"
    End If
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.MousePointer = 12
End Sub


在运行此程序前,一定要先准备两个图标文件,1.ico  和 2.ico 这两个文件保存到C盘根目录里。
程序运行后,把鼠标光标移到某个控件中,鼠标光标变为自定义的形状,此时如果按 下鼠标右键,则显示相应的信息。

来源:visual basic程序设计教程第四版答案(刘炳文)

本文链接:http://www.wb98.com/vb1/post/vb_10.9.html

本站文章搜索:

<< 上一篇下一篇 >>

搜索

Tags列表

扫我手机登录

赞助商链接