先谢谢了. 根据您的方法,我是这样处理的. Private Sub frmMain_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown, _ lbl1.MouseDown, lbl2.MouseDown, lbl3.MouseDown, lbl4.MouseDown, _ lbl5.MouseDown, lbl6.MouseDown, lbl7.MouseDown If e.Button And MouseButtons.Left Then
MousePoint.X = e.X MousePoint.Y = e.Y If lbl1.MouseButtons Then MousePoint.Y += lbl1.Top ElseIf lbl2.MouseButtons Then MousePoint.Y += lbl2.Top ElseIf lbl3.MouseButtons Then MousePoint.Y += lbl3.Top ElseIf lbl4.MouseButtons Then MousePoint.Y += lbl4.Top ElseIf lbl5.MouseButtons Then MousePoint.Y += lbl5.Top ElseIf lbl6.MouseButtons Then MousePoint.Y += lbl6.Top ElseIf lbl7.MouseButtons Then MousePoint.Y += lbl7.Top End If End If End Sub出现的问题是,一是MousePoint.Y依然不能正确的取到值,二是我觉得写得比较笨拙,不知道如何改进.
Private Sub Label1_MouseDown(index As Integer, ButtonConstants As Integer, Shift As Integer, X As Single, Y As Single) Label1(index) = "相对窗体X坐标" & X + Label1(index).Left & "相对窗体Y坐标" & Y + Label1(index).Top End Sub
谢谢楼上的各位兄弟了.最后我还是对每个LABEL点击事件进行了处理,取得相对LABEL的坐标,换算成相对FORM的坐标. 下面的是程序. Private Sub lbl1_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl1.MouseDown If e.Button And MouseButtons.Left Then MousePoint.X = e.X MousePoint.Y = e.Y + lbl1.Top End If End Sub Private Sub lbl2_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseDown If e.Button And MouseButtons.Left Then MousePoint.X = e.X MousePoint.Y = e.Y + lbl2.Top End If End Sub我原来的想法是在点击FORM的处理中加LABEL的识别判断,如果可以实现,能节约不少步骤. 楼上的说得对,用数组还是解决不了问题.
我真正想知道的就是一楼程序中的下列部分 If lbl1.MouseButtons Then MousePoint.Y += lbl1.Top ElseIf lbl2.MouseButtons Then MousePoint.Y += lbl2.Top ElseIf lbl3.MouseButtons Then MousePoint.Y += lbl3.Top ElseIf lbl4.MouseButtons Then MousePoint.Y += lbl4.Top ElseIf lbl5.MouseButtons Then MousePoint.Y += lbl5.Top ElseIf lbl6.MouseButtons Then MousePoint.Y += lbl6.Top ElseIf lbl7.MouseButtons Then MousePoint.Y += lbl7.Top End If判断条件是错误的.
和你的鼠标在label中的(x、y)位置相加
根据您的方法,我是这样处理的. Private Sub frmMain_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown, _
lbl1.MouseDown, lbl2.MouseDown, lbl3.MouseDown, lbl4.MouseDown, _
lbl5.MouseDown, lbl6.MouseDown, lbl7.MouseDown If e.Button And MouseButtons.Left Then
MousePoint.X = e.X
MousePoint.Y = e.Y If lbl1.MouseButtons Then
MousePoint.Y += lbl1.Top
ElseIf lbl2.MouseButtons Then
MousePoint.Y += lbl2.Top
ElseIf lbl3.MouseButtons Then
MousePoint.Y += lbl3.Top
ElseIf lbl4.MouseButtons Then
MousePoint.Y += lbl4.Top
ElseIf lbl5.MouseButtons Then
MousePoint.Y += lbl5.Top
ElseIf lbl6.MouseButtons Then
MousePoint.Y += lbl6.Top
ElseIf lbl7.MouseButtons Then
MousePoint.Y += lbl7.Top
End If
End If
End Sub出现的问题是,一是MousePoint.Y依然不能正确的取到值,二是我觉得写得比较笨拙,不知道如何改进.
Label1(index) = "相对窗体X坐标" & X + Label1(index).Left & "相对窗体Y坐标" & Y + Label1(index).Top
End Sub
的确控件数组用着不方便。
楼主提供的代码本来没有问题,就是在那里可以改:
你按下哪个lbl,那么sender就是那个lbl。
你根据这个来改代码吧。
下面的是程序. Private Sub lbl1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl1.MouseDown If e.Button And MouseButtons.Left Then MousePoint.X = e.X
MousePoint.Y = e.Y + lbl1.Top End If
End Sub Private Sub lbl2_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbl2.MouseDown If e.Button And MouseButtons.Left Then MousePoint.X = e.X
MousePoint.Y = e.Y + lbl2.Top End If
End Sub我原来的想法是在点击FORM的处理中加LABEL的识别判断,如果可以实现,能节约不少步骤.
楼上的说得对,用数组还是解决不了问题.
If lbl1.MouseButtons Then
MousePoint.Y += lbl1.Top
ElseIf lbl2.MouseButtons Then
MousePoint.Y += lbl2.Top
ElseIf lbl3.MouseButtons Then
MousePoint.Y += lbl3.Top
ElseIf lbl4.MouseButtons Then
MousePoint.Y += lbl4.Top
ElseIf lbl5.MouseButtons Then
MousePoint.Y += lbl5.Top
ElseIf lbl6.MouseButtons Then
MousePoint.Y += lbl6.Top
ElseIf lbl7.MouseButtons Then
MousePoint.Y += lbl7.Top
End If判断条件是错误的.