我正在使用以下代码根据光标位置更改光标图像。我注意到,如果光标穿过标签或文本框或其他东西,光标将不会改变,直到它进入我的tablelayout的一部分,这可能会改变页面的中间部分。
Private Sub TableLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseMove
If e.Location.X > Me.Width - 7 And e.Location.Y > 12 And e.Location.Y < Me.Height - 12 Then
Me.Cursor = Cursors.SizeWE
ElseIf e.Location.X < 6 And e.Location.Y > 12 And e.Location.Y < Me.Height - 12 Then
Me.Cursor = Cursors.SizeWE
ElseIf e.Location.Y > Me.Width - 12 And e.Location.X > 12 And e.Location.X < Me.Width - 12 Then
Me.Cursor = Cursors.SizeNS
ElseIf e.Location.Y < 6 And e.Location.X > 12 And e.Location.X < Me.Width - 12 Then
Me.Cursor = Cursors.SizeNS
Else
Me.Cursor = Cursors.Default
End If
End Sub
我想知道的是,是否有一个不同的mousemove事件只会集中在光标位置而不是它的行进位置。我尝试过用鼠标移动,但是没办法。
希望这是有道理的。
答案 0 :(得分:0)
您可以使用单一方法处理父MouseMove
及其所有子级的TableLayoutPanel
事件,并根据需要简单地翻译位置。
Private Sub TableLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseMove
Dim ctrl = DirectCast(sender, Control)
Dim location = TableLayoutPanel1.PointToClient(ctrl.PointToScreen(e.Location))
'location is now a Point relative the the top-left corner of TableLayoutPanel1.
'...
End Sub
Private Sub HandleMouseMoveForTableChildren()
For Each child As Control In TableLayoutPanel1.Controls
RemoveHandler child.MouseMove, AddressOf TableLayoutPanel1_MouseMove
AddHandler child.MouseMove, AddressOf TableLayoutPanel1_MouseMove
Next
End Sub
只要将子控件添加到表中,就可以调用该secoind方法,然后第一个方法将按您的意愿工作。