Click here to Skip to main content
15,850,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, I've tried really everything, searched everywhere, but my class derived from Richtextbox (WinForm) in Net 4.0 absolutely refuses to show the mouse cursor (right-sloping arrow) in the text selection area ( entire line) so to speak "SelectionMargin". To be precise, it appears and disappears a moment later. The classroom is empty, there are no events that could disturb it. Furthermore, there is little or nothing on this topic online, as if it were a secret to be kept. Thanks everyone and sorry for the bad translation.

What I have tried:

This is the code that gave me the best result, but it's a stretch and it still flashes from time to time.

.NET
Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)

        With Me

            If Not .ClientRectangle.Contains(e.Location) Then
                .Capture = False
            ElseIf Not .Capture Then
                .Capture = True
            End If

            Cursor = Cursors.IBeam

            Dim X = PointToClient(Control.MousePosition).X

            If X <= Me.SelectionIndent Then
                Cursor = Cursors.Arrow
            Else
                Cursor = Cursors.IBeam
            End If

        End With

        MyBase.OnMouseMove(e)

    End Sub
Posted
Updated 8-Nov-23 7:28am
v2
Comments
Gerry Schmitz 8-Nov-23 13:22pm    
You set the cursor "once"; you don't keep hitting it with every "increment" in a mouse move. Figure out a "mode" that toggles the cursor; not hammers it.

1 solution

I hadn't thought of that, it seems to work. Thank you

VB
Dim X = PointToClient(Control.MousePosition).X

            If X <= Me.SelectionIndent Then
                If Cursor = Cursors.Arrow Then
                    Exit Sub
                End If
                Cursor = Cursors.Arrow
            Else
                If Cursor = Cursors.IBeam Then
                    Exit Sub
                End If
                Cursor = Cursors.IBeam
            End If
 
Share this answer
 
v2
Comments
Gerry Schmitz 9-Nov-23 13:45pm    
Glad it made sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900