Relative Cursor Position

Nidonocu

New member
Joined
Sep 26, 2005
Messages
2
Location
Sheffield, UK
Programming Experience
Beginner
My first post, hope this is in the right place. :)
I'm trying to get some code which displays the nearest character to a point on my rich text box control for then later finding a perticular character and I've been expriementing with different code to try and do this. This code below is the closest I have so far but for some reason (0, 0) is in the wrong place. I've attached an image, the green dot shows where I want it to be and the red dot shows about where the mouse was when the screencap was taken, the status bar label (CharIdx) showing 0, 0 as the location.

VB.NET:
	Private Sub FormMain_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
		Dim pikachu As New Point(System.Windows.Forms.Cursor.Position)
		Dim raichu As New Point(RichTextBoxOutput.Location)
		Dim pichu As New Point(Me.Location)
		Dim bulbasaur As Integer = RichTextBoxOutput.GetCharIndexFromPosition(pikachu - (raichu + pichu))
		Dim charmander As String = RichTextBoxOutput.GetCharFromPosition(pikachu - (raichu + pichu))
		CharIdx.Text = Convert.ToString(bulbasaur) & " - " & charmander & " - " & Convert.ToString(pikachu - (raichu + pichu))
	End Sub
Sorry about the variable names. :rolleyes:
 

Attachments

  • xyprob.png
    xyprob.png
    16.2 KB · Views: 87
Wow.. talk about a great way for me to enter the forum. x.X Guess what happens no more than half an hour after I post this? :eek: I discover that GetPostitionfromCharIndex() is what I needed and PointToClient() was what I needed for my problem above to relative positioning.
To clarifiy I wanted to write some code so that as output is added to my box, if the user currently has the last line in view it will use the Append method and thusly autoscroll.
If the user is viewing the backlog, the control adds text with control.text = control.text + newcontent method.
If think I have all I need now and I can scan to see if the last character's y position (derived from text length) is within the control's height size, then choose the correct method as needed.
 
Back
Top