在窗體上畫一個文本框、一個圖片框和一個命令按鈕。編寫程序,使得當鼠標光標位于不同的控件或窗體上時,鼠標光標具有不同的形狀,此時如果按下鼠標右鍵,則顯示相應的信息。例如,當鼠標光標移到圖片框上時,如果按下鼠標右鍵,則用一個信息框顯示:“現在鼠標光標位于圖片框中”。要求:在文本框和窗體上的鼠標光標使用系統提供的光標形狀,而圖片框和命令按鈕上的鼠標光標使用自定義的形狀。

    解:在窗體上_ 一個文本框、一個圖片框和一個命令按鈕,然后編寫如下程序。
 
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列表

掃我手機登錄

贊助商鏈接

黑龙江22选5开奖结果