Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

line number

Posted on 2007-03-30
2
Medium Priority
?
172 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 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

730 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