2014-06-18 62 views
2

我正在製作一個流程圖程序。我做了所有這些,但是我面對這個問題。 如何通過獲取鼠標的位置在Visual Basic中的兩個按鈕之間動態地繪製一條線(連接線)!!如何在窗體中繪製一條線來連接vb6中的兩個對象

所以這裏是它的代碼。我做了如何獲得遊標的位置,但我不能前進。

Option Explicit 

Private Type POINTAPI 
    x As Long 
    y As Long 
End Type 

Private Declare Function GetCursorPos Lib "user32" _ 
    (lpPoint As POINTAPI) As Long 

Dim z As POINTAPI 

Private Sub Form_Load() 
    Timer1.Interval = 1 
    Timer1.Enabled = True 
End Sub 

Private Sub Timer1_Timer() 
    GetCursorPos z 
    Label1 = "x: " & z.x 
    Label2 = "y: " & z.y 
End Sub 

請幫助我們解決這個問題! 在此先感謝

回答

1

爲什麼你需要鼠標的位置?

看看下面的測試項目:

'1 form with: 
' 2 command buttons: name=Command1 name=Command2 
Option Explicit 

Private Sub ConnectButtons(cmd1 As CommandButton, cmd2 As CommandButton) 
    Dim sngX1 As Single, sngX2 As Single 
    Dim sngY1 As Single, sngY2 As Single 
    With cmd1 
    sngX1 = .Left + .Width 
    sngY1 = .Top + .Height/2 
    End With 'cmd1 
    With cmd2 
    sngX2 = .Left 
    sngY2 = .Top + .Height/2 
    End With 'cmd2 
    Line (sngX1, sngY1)-(sngX2, sngY2) 
End Sub 

Private Sub Form_Click() 
    ConnectButtons Command1, Command2 
End Sub 

Private Sub Form_Resize() 
    Command1.Move 120, 120 
    Command2.Move ScaleWidth/2, ScaleHeight/2 
End Sub 

當你運行它,它會顯示在窗體上2個命令按鈕,當你點擊它會繪製連接線形態上

調整窗體大小以更改Command2的位置並再次單擊窗體

注意您傳遞給ConnectButtons子項的命令按鈕的順序

相關問題