如果只有一条还好办:用Label控件透明化覆盖在Line上Click事件交给Label。

解决方案 »

  1.   

    不是,我有许多line,我想知道是选择了哪一条?
      

  2.   

    你用image控件不就行了!在load一张线条的图片!ok!
      

  3.   

    自己运算获得呀,
    利用鼠标mousedown事件里的两个参数x,y来判断是否点在了线上.在把该线高亮显示.
    嘿嘿,应该就可以咯.
      

  4.   

    我用的是line数组,如果一个一个纪录坐标的话,太多了,还有没有其他办法!
      

  5.   

    你的数组有多少个元素?几百个元素用坐标来记录完全没有问题。我有一个程序,每次生成500个左右点,也是用检查点击坐标的方式,判断是否发生click事件,在amd k6 233 上跑速度都没有问题。
      

  6.   

    别用数组了,用对象,每次对鼠标的点击进行处理,然后枚举对象的坐标进行比较,别说在amd k6 233 上了,在133上也照样能跑,速度也没有问题啊
      

  7.   

    我找到了!用LineDDA 的API函数,下面是代码:'Form1代码Option Explicit'Private Sub Command1_Click()
    '    LineDDA 100, 100, 105, 105, AddressOf LineDDAProc, 0
    'End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim i As Integer, selected As Boolean
        
        nPoints = 0
        LineDDA 20, 20, 200, 200, AddressOf LineDDAProc, 0
        For i = 0 To nPoints - 1
            If ((pX(i) - X) ^ 2 + (pY(i) - Y) ^ 2) ^ 0.5 < 3 Then
                MsgBox "您点选的是 (20, 20) - (200, 200) 线段!"
                selected = True
                Exit For
            End If
        Next
        
        nPoints = 0
        LineDDA 20, 150, 200, 50, AddressOf LineDDAProc, 0
        For i = 0 To nPoints - 1
            If ((pX(i) - X) ^ 2 + (pY(i) - Y) ^ 2) ^ 0.5 < 3 Then
                MsgBox "您点选的是 (20, 150) - (200, 50) 线段!重画Line1!"
                Line1.X1 = 2400
                Line1.Y1 = 4800
                Line1.X2 = 3000
                Line1.Y2 = 1800
                selected = True
                Exit For
            End If
        Next
        
        
        nPoints = 0
        LineDDA 240, 300, 480, 180, AddressOf LineDDAProc, 0
        For i = 0 To nPoints - 1
            If ((pX(i) - X) ^ 2 + (pY(i) - Y) ^ 2) ^ 0.5 < 3 Then
                MsgBox "您点选的是 240, 300, 480, 180 线段!"
                selected = True
                Exit For
            End If
        Next    If Not selected Then
            MsgBox "您没有点选到任何线段!"
        End If
        
    End SubPrivate Sub Form_Paint()
        Me.ScaleMode = vbPixels
        Line (20, 20)-(200, 200)
        Line (20, 150)-(200, 50)
        Line (240, 300)-(480, 180)
    End Sub
    ****************************************************************
    'Module1代码Option ExplicitDeclare Function LineDDA Lib "gdi32" (ByVal n1 As Long, ByVal n2 As Long, ByVal n3 As Long, ByVal n4 As Long, ByVal lpLineDDAProc As Long, ByVal lParam As Long) As LongPublic pX(2048) As Long
    Public pY(2048) As Long
    Public nPoints As IntegerSub LineDDAProc(ByVal X As Long, ByVal Y As Long, ByVal lpData As Long)
        pX(nPoints) = X
        pY(nPoints) = Y
        nPoints = nPoints + 1
    End Sub