Solved

line number

Posted on 2007-03-30
2
165 Views
Last Modified: 2010-04-23
How can I return the line number of a multiline text box?
0
Comment
Question by:thenrich
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now