Solved

line number

Posted on 2007-03-30
2
168 Views
Last Modified: 2010-04-23
How can I return the line number of a multiline text box?
0
Comment
Question by:thenrich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:paix120
ID: 18826587
Well, I've never tried this, but here are a few ideas:

I've heard you can try to write a function to cound the number of ASCII return characters chr(10) before the current cursor position in a rich text box.

Or, if your textbox is going to remain a fixed size (i.e. not resize with the window), you could use a fixed-width font and figure out how many characters fit on a line, and divide the number of characters before the cursor by the characters per line.

EDIT: I just looked and found this code that should help

http://www.freevbcode.com/ShowCode.Asp?ID=2493
0
 
LVL 28

Accepted Solution

by:
iboutchkine earned 250 total points
ID: 18835648
this will return the current line number

<System.Runtime.InteropServices.DllImport("user32")> Shared Function _
    SendMessage(ByVal hWnd As Integer, ByVal wMsg As Integer, _
    ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function

' Determine the current line in a multiline TextBox control
' Example: MessageBox.Show(GetTextBoxCurrentLine(TextBox1))

Function GetTextBoxCurrentLine(ByVal tb As TextBox) As Integer
    Const EM_LINEFROMCHAR As Integer = &HC9
    Return SendMessage(tb.Handle.ToInt32(), EM_LINEFROMCHAR, -1, 0) + 1
End Function
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question