Determining RichTextBox Current Column Location

G

Guest

How do I determine the column associated with the current edit location within a RichTextBox? The following code allow
me to determine the current line

txtLineNumber.Text = FormatNumber(RichTextBox1.GetLineFromCharIndex(RichTextBox1.SelectionStart())+1,0

How do I determine the column location within the line? I must be missing something obvious, any help would be appreciated
 
G

Guest

Well I decided to fiddle around with the text files is was dealing with and came up with thi
option

Dim x As Integer = RichTextBox1.SelectionStart(
Do While x >
If RichTextBox1.Text.Chars(x-1) = vbLF Then Exit Do Else x -=
Loo
Return (RichTextBox1.SelectionStart() - x

Just backs-up from the current entry point until it hits a Line Feed character. Th
distance between the insertion point and the beginning of the line is returned.
Obvious pit-fall is the character which is intercepted when the end of the curren
line is encountered. If x=0, all text has been read.

If anyone has ideas to improve this option, or has an improved solution, an
contribution would be appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top