Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在鼠标按下或基于鼠标按钮更新控制光标_.net_Vb.net_Mouse Cursor - Fatal编程技术网

.net 在鼠标按下或基于鼠标按钮更新控制光标

.net 在鼠标按下或基于鼠标按钮更新控制光标,.net,vb.net,mouse-cursor,.net,Vb.net,Mouse Cursor,在鼠标移动事件中,当鼠标左键=鼠标左键时,我无法更改鼠标光标 在“文本控制坐标”文本框中的gif图像中,您可以看到我正在使用光标应更新到的内容的条目更新此文本框。这是底部方框中的最后一个条目。光标设置为“SizeAll”,但当我使用鼠标左键移动控件时,我有代码将控件光标设置为“Hand”。文本框显示已正确达到将光标更新为“手”的逻辑。问题是,只有在我释放鼠标左键后,光标才会更新。它会一直这样做,直到我再次开始移动鼠标,MouseMove事件再次接管 Private Sub ClsTextObj

在鼠标移动事件中,当鼠标左键=鼠标左键时,我无法更改鼠标光标

在“文本控制坐标”文本框中的gif图像中,您可以看到我正在使用光标应更新到的内容的条目更新此文本框。这是底部方框中的最后一个条目。光标设置为“SizeAll”,但当我使用鼠标左键移动控件时,我有代码将控件光标设置为“Hand”。文本框显示已正确达到将光标更新为“手”的逻辑。问题是,只有在我释放鼠标左键后,光标才会更新。它会一直这样做,直到我再次开始移动鼠标,MouseMove事件再次接管

Private Sub ClsTextObj_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    ' Get object under cursor when user moved mouse - MouseMove
    ' We are only going to perform the WORK if the object is TypeOf clsTextObj
    If TypeOf sender Is clsTextObj Then
        Dim txt_clsText_ctrl_tmp = DirectCast(sender, clsTextObj)

        'Declare Bool to determine if Left Mouse Button is being used
        Dim IsMouseLeftButton = e.Button = Windows.Forms.MouseButtons.Left

        Dim mCursor As Cursor
        Dim MouseCursor = "Logic Never Reached"

        'Set mCursor var to the hand cursor when the LEFT Mouse Button is being used
        If IsMouseLeftButton Then
            MouseCursor = "Hand"
            mCursor = Cursors.Hand
        Else
            MouseCursor = "SizeAll"
            mCursor = Cursors.SizeAll
        End If

        'START Determine Mouse Cursor - Find where the mouse cursor is within the control
        Dim MouseIsInLeftEdge As Boolean
        Dim MouseIsInRightEdge As Boolean
        Dim MouseIsInTopEdge As Boolean
        Dim MouseIsInBottomEdge As Boolean

        MouseIsInLeftEdge = Math.Abs(e.X) <= 9
        MouseIsInRightEdge = Math.Abs(e.X - txt_clsText_ctrl_tmp.Width) <= 9
        MouseIsInTopEdge = Math.Abs(e.Y) <= 9
        MouseIsInBottomEdge = Math.Abs(e.Y - txt_clsText_ctrl_tmp.Height) <= 9

        If MouseIsInLeftEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf MouseIsInRightEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf (MouseIsInTopEdge Or MouseIsInBottomEdge) Then
            txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNS
        Else
            txt_clsText_ctrl_tmp.Appearance.Cursor = mCursor
            'txt_clsText_ctrl_tmp.Appearance.Cursor = Cursor.SizeAll
        End If
        'END Determining Mouse Cursor

        'Capture Mouse Down Clicks while moving mouse cursor.  Mouse Move overrides Mouse Down basically and so we capture mouse down buttons while moving here
        'If e.Button = Windows.Forms.MouseButtons.Left Then
        If IsMouseLeftButton Then
            txt_clsText_ctrl.Appearance.Cursor = Cursors.Hand
            txt_clsText_ctrl.Location = New Point(txt_clsText_ctrl.Location.X + (e.X - initialClickLocation.X), txt_clsText_ctrl.Location.Y + (e.Y - initialClickLocation.Y))
        End If

        'Output mouse details
        ClsTextObj1.Value = "X: " & txt_clsText_ctrl_tmp.Location.X + e.X _
                          & ",Y: " & txt_clsText_ctrl_tmp.Location.Y + e.Y

        'Build User output info
        builder.Clear()
        builder.Append("Control Name: " & txt_clsText_ctrl_tmp.Name).AppendLine()
        builder.Append("e.X " & e.X & ", e.Y: " & e.Y).AppendLine()
        builder.Append("e.Point Location: " & e.Location.ToString()).AppendLine()
        builder.Append("txt_clsText_ctrl Point Location: " & txt_clsText_ctrl_tmp.Location.ToString()).AppendLine()
        builder.Append("Form Location: {X=" & txt_clsText_ctrl_tmp.Location.X + e.X)
        builder.Append(",Y=" & txt_clsText_ctrl_tmp.Location.Y + e.Y & "}").AppendLine()
        builder.Append("initial Ctrl Location: " & initialCtrlLocation.ToString()).AppendLine()
        builder.Append("initial Click Location: " & initialClickLocation.ToString()).AppendLine()
        builder.Append("Calc Point: " & "X: " & (e.X - initialClickLocation.X))
        builder.Append(",Y: " & (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("New Label Pos: " & "X: " & txt_clsText_ctrl_tmp.Location.X + (e.X - initialClickLocation.X))
        builder.Append(",Y: " & txt_clsText_ctrl_tmp.Location.Y + (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("Mouse Button: " & e.Button.ToString()).AppendLine()
        builder.Append("Left Edge: " & MouseIsInLeftEdge).AppendLine()
        builder.Append("Right Edge: " & MouseIsInRightEdge).AppendLine()
        builder.Append("Top Edge: " & MouseIsInTopEdge).AppendLine()
        builder.Append("Bottom Edge: " & MouseIsInBottomEdge).AppendLine()
        builder.Append("Cursor: " & appendMouseCursor)

        ClsTextObj2.Value = builder.ToString()

    End If
End Sub
因为我使用的是表单游标,所以我必须确保将其更新回默认值。我发现MouseUp很适合这个。至少我还没有遇到任何bug

Private Sub ClsTextObj_MouseUp(sender As Object, e As MouseEventArgs)
    If TypeOf sender Is STORE.PDFBuilder.clsTextObj Then
        Dim txt_clsText_ctrl_tmp = DirectCast(sender, STORE.PDFBuilder.clsTextObj)

        IsMouseDown = False
        Me.Cursor = Cursors.Default

    End If
End Sub
最后,对于任何正常的.NET控件,您都可以使用相同的代码,但我不必使用
Control.Appearance.Cursor
-->您可以使用
Control.Cursor


Jimi轻轻推了一下,我使用表单光标作为基础设施控件,但无论出于何种原因使用鼠标按钮时,无法更新鼠标光标。我改为使用表单游标。代码如下:

Private Sub ClsTextObj_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    ' Get object under cursor when user moved mouse - MouseMove
    ' We are only going to perform the WORK if the object is TypeOf clsTextObj
    If TypeOf sender Is clsTextObj Then
        Dim txt_clsText_ctrl_tmp = DirectCast(sender, clsTextObj)

        Dim IsMouseLeftButton = e.Button = Windows.Forms.MouseButtons.Left

        Dim mCursor As Cursor
        Dim MouseCursor = "Logic Never Reached"

        If IsMouseLeftButton And IsMouseDown Then
            MouseCursor = "Hand"    'Used to output info to screen
            mCursor = Cursors.Hand
        Else
            MouseCursor = "SizeAll" 'Used to output info to screen
            mCursor = Cursors.SizeAll
        End If

        'START Determine Mouse Cursor - Find where the mouse cursor is within the control
        Dim MouseIsInLeftEdge As Boolean
        Dim MouseIsInRightEdge As Boolean
        Dim MouseIsInTopEdge As Boolean
        Dim MouseIsInBottomEdge As Boolean

        MouseIsInLeftEdge = Math.Abs(e.X) <= 9
        MouseIsInRightEdge = Math.Abs(e.X - txt_clsText_ctrl_tmp.Width) <= 9
        MouseIsInTopEdge = Math.Abs(e.Y) <= 9
        MouseIsInBottomEdge = Math.Abs(e.Y - txt_clsText_ctrl_tmp.Height) <= 9

        If MouseIsInLeftEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf MouseIsInRightEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf (MouseIsInTopEdge Or MouseIsInBottomEdge) Then
            txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNS
        Else
            txt_clsText_ctrl_tmp.Appearance.Cursor = mCursor
        End If
        'END Determining Mouse Cursor

        'Capture Mouse Down Clicks while moving mouse cursour.  Mouse Move overrides Mouse Down basically and so we capture mouse down buttons while moving here
        'If e.Button = Windows.Forms.MouseButtons.Left Then
        If IsMouseLeftButton Then 'And IsMouseDown Then
            Me.Cursor = mCursor
            txt_clsText_ctrl.Location = New Point(txt_clsText_ctrl.Location.X + (e.X - initialClickLocation.X), txt_clsText_ctrl.Location.Y + (e.Y - initialClickLocation.Y))
        End If


        ClsTextObj1.Value = "X: " & txt_clsText_ctrl_tmp.Location.X + e.X _
                          & ",Y: " & txt_clsText_ctrl_tmp.Location.Y + e.Y

        'Build User output info
        builder.Clear()
        builder.Append("Control Name: " & txt_clsText_ctrl_tmp.Name).AppendLine()
        builder.Append("e.X " & e.X & ", e.Y: " & e.Y).AppendLine()
        builder.Append("e.Point Location: " & e.Location.ToString()).AppendLine()
        builder.Append("txt_clsText_ctrl Point Location: " & txt_clsText_ctrl_tmp.Location.ToString()).AppendLine()
        builder.Append("Form Location: {X=" & txt_clsText_ctrl_tmp.Location.X + e.X)
        builder.Append(",Y=" & txt_clsText_ctrl_tmp.Location.Y + e.Y & "}").AppendLine()
        builder.Append("initial Ctrl Location: " & initialCtrlLocation.ToString()).AppendLine()
        builder.Append("initial Click Location: " & initialClickLocation.ToString()).AppendLine()
        builder.Append("Calc Point: " & "X: " & (e.X - initialClickLocation.X))
        builder.Append(",Y: " & (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("New Label Pos: " & "X: " & txt_clsText_ctrl_tmp.Location.X + (e.X - initialClickLocation.X))
        builder.Append(",Y: " & txt_clsText_ctrl_tmp.Location.Y + (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("Mouse Button: " & e.Button.ToString()).AppendLine()
        builder.Append("Left Edge: " & MouseIsInLeftEdge).AppendLine()
        builder.Append("Right Edge: " & MouseIsInRightEdge).AppendLine()
        builder.Append("Top Edge: " & MouseIsInTopEdge).AppendLine()
        builder.Append("Bottom Edge: " & MouseIsInBottomEdge).AppendLine()
        builder.Append("Cursor: " & MouseCursor).AppendLine()
        builder.Append("Is Mouse Down: " & IsMouseDown).AppendLine()
        builder.Append("Is Mouse Left: " & IsMouseLeftButton)

        ClsTextObj2.Value = builder.ToString()

    End If

End Sub

Private Sub ClsTextObj_MouseDown(sender As Object, e As MouseEventArgs)
    ' Get object under cursor when user clicked MouseDown
    If TypeOf sender Is clsTextObj Then

        initialClickLocation = New Point(e.X, e.Y)

        txt_clsText_ctrl = DirectCast(sender, clsTextObj)

        IsMouseDown = True

        initialCtrlLocation = txt_clsText_ctrl.Location

        'ListView Stuff
        updateListView()

    End If
End Sub

Private Sub ClsTextObj_MouseUp(sender As Object, e As MouseEventArgs)

    IsMouseDown = False
    Me.Cursor = Cursors.Default

End Sub
Private Sub-ClsTextObj_MouseMove(ByVal sender作为对象,ByVal e作为System.Windows.Forms.MouseEventArgs)
'当用户移动鼠标时获取光标下的对象-MouseMove
“只有当对象是TypeOf clsTextObj时,我们才会执行该工作
如果发送方类型为clsTextObj,则
Dim txt\U clsText\U ctrl\U tmp=DirectCast(发送方,clsTextObj)
Dim IsMouseLeftButton=e.按钮=Windows.Forms.MouseButtons.Left
作为光标的Dim mCursor
Dim MouseCursor=“未达到逻辑”
如果IsMouseLeftButton和IsMouseDown,则
MouseCursor=“Hand”用于将信息输出到屏幕
mCursor=光标。手动
其他的
MouseCursor=“SizeAll”'用于将信息输出到屏幕
mCursor=Cursors.SizeAll
如果结束
'开始确定鼠标光标-查找鼠标光标在控件中的位置
作为布尔值的Dim MouseIsInLeftEdge
将鼠标右边缘设置为布尔值
模糊鼠标输入为布尔值
将鼠标底部边缘设置为布尔值

MouseIsInLeftEdge=Math.Abs(e.X)什么是
clsTextObj
?文本框派生类?它的
外观
属性执行什么功能?设置/定义光标类型/样式?您应该检查该代码。该部分“Dim IsMouseLeftButton=e.Button=Windows.Forms.MouseButtons.Left”是否正常工作?我支持的应用程序使用由名为Infragistitcs的公司创建的第三部分控件。我写了一些与我现在在C#中所做的非常相似的东西,但它使用标准的.NET控件,并且工作得非常完美@Jimi让我想到,由于在外观属性中我无法访问的代码,我应该使用表单游标。我更新了代码,以在使用鼠标左键时将表单光标更新到手上。这很有效。
Private Sub ClsTextObj_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    ' Get object under cursor when user moved mouse - MouseMove
    ' We are only going to perform the WORK if the object is TypeOf clsTextObj
    If TypeOf sender Is clsTextObj Then
        Dim txt_clsText_ctrl_tmp = DirectCast(sender, clsTextObj)

        Dim IsMouseLeftButton = e.Button = Windows.Forms.MouseButtons.Left

        Dim mCursor As Cursor
        Dim MouseCursor = "Logic Never Reached"

        If IsMouseLeftButton And IsMouseDown Then
            MouseCursor = "Hand"    'Used to output info to screen
            mCursor = Cursors.Hand
        Else
            MouseCursor = "SizeAll" 'Used to output info to screen
            mCursor = Cursors.SizeAll
        End If

        'START Determine Mouse Cursor - Find where the mouse cursor is within the control
        Dim MouseIsInLeftEdge As Boolean
        Dim MouseIsInRightEdge As Boolean
        Dim MouseIsInTopEdge As Boolean
        Dim MouseIsInBottomEdge As Boolean

        MouseIsInLeftEdge = Math.Abs(e.X) <= 9
        MouseIsInRightEdge = Math.Abs(e.X - txt_clsText_ctrl_tmp.Width) <= 9
        MouseIsInTopEdge = Math.Abs(e.Y) <= 9
        MouseIsInBottomEdge = Math.Abs(e.Y - txt_clsText_ctrl_tmp.Height) <= 9

        If MouseIsInLeftEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf MouseIsInRightEdge Then
            If MouseIsInTopEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNESW
            ElseIf MouseIsInBottomEdge Then
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNWSE
            Else
                txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeWE
            End If
        ElseIf (MouseIsInTopEdge Or MouseIsInBottomEdge) Then
            txt_clsText_ctrl_tmp.Appearance.Cursor = Cursors.SizeNS
        Else
            txt_clsText_ctrl_tmp.Appearance.Cursor = mCursor
        End If
        'END Determining Mouse Cursor

        'Capture Mouse Down Clicks while moving mouse cursour.  Mouse Move overrides Mouse Down basically and so we capture mouse down buttons while moving here
        'If e.Button = Windows.Forms.MouseButtons.Left Then
        If IsMouseLeftButton Then 'And IsMouseDown Then
            Me.Cursor = mCursor
            txt_clsText_ctrl.Location = New Point(txt_clsText_ctrl.Location.X + (e.X - initialClickLocation.X), txt_clsText_ctrl.Location.Y + (e.Y - initialClickLocation.Y))
        End If


        ClsTextObj1.Value = "X: " & txt_clsText_ctrl_tmp.Location.X + e.X _
                          & ",Y: " & txt_clsText_ctrl_tmp.Location.Y + e.Y

        'Build User output info
        builder.Clear()
        builder.Append("Control Name: " & txt_clsText_ctrl_tmp.Name).AppendLine()
        builder.Append("e.X " & e.X & ", e.Y: " & e.Y).AppendLine()
        builder.Append("e.Point Location: " & e.Location.ToString()).AppendLine()
        builder.Append("txt_clsText_ctrl Point Location: " & txt_clsText_ctrl_tmp.Location.ToString()).AppendLine()
        builder.Append("Form Location: {X=" & txt_clsText_ctrl_tmp.Location.X + e.X)
        builder.Append(",Y=" & txt_clsText_ctrl_tmp.Location.Y + e.Y & "}").AppendLine()
        builder.Append("initial Ctrl Location: " & initialCtrlLocation.ToString()).AppendLine()
        builder.Append("initial Click Location: " & initialClickLocation.ToString()).AppendLine()
        builder.Append("Calc Point: " & "X: " & (e.X - initialClickLocation.X))
        builder.Append(",Y: " & (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("New Label Pos: " & "X: " & txt_clsText_ctrl_tmp.Location.X + (e.X - initialClickLocation.X))
        builder.Append(",Y: " & txt_clsText_ctrl_tmp.Location.Y + (e.Y - initialClickLocation.Y)).AppendLine()
        builder.Append("Mouse Button: " & e.Button.ToString()).AppendLine()
        builder.Append("Left Edge: " & MouseIsInLeftEdge).AppendLine()
        builder.Append("Right Edge: " & MouseIsInRightEdge).AppendLine()
        builder.Append("Top Edge: " & MouseIsInTopEdge).AppendLine()
        builder.Append("Bottom Edge: " & MouseIsInBottomEdge).AppendLine()
        builder.Append("Cursor: " & MouseCursor).AppendLine()
        builder.Append("Is Mouse Down: " & IsMouseDown).AppendLine()
        builder.Append("Is Mouse Left: " & IsMouseLeftButton)

        ClsTextObj2.Value = builder.ToString()

    End If

End Sub

Private Sub ClsTextObj_MouseDown(sender As Object, e As MouseEventArgs)
    ' Get object under cursor when user clicked MouseDown
    If TypeOf sender Is clsTextObj Then

        initialClickLocation = New Point(e.X, e.Y)

        txt_clsText_ctrl = DirectCast(sender, clsTextObj)

        IsMouseDown = True

        initialCtrlLocation = txt_clsText_ctrl.Location

        'ListView Stuff
        updateListView()

    End If
End Sub

Private Sub ClsTextObj_MouseUp(sender As Object, e As MouseEventArgs)

    IsMouseDown = False
    Me.Cursor = Cursors.Default

End Sub