Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GetFirstCharIndexFromLine Method

TextBoxBase.GetFirstCharIndexFromLine Method

Retrieves the index of the first character of a given line.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public int GetFirstCharIndexFromLine (
	int lineNumber
public int GetFirstCharIndexFromLine (
	int lineNumber
public function GetFirstCharIndexFromLine (
	lineNumber : int
) : int
Not applicable.



The line for which to get the index of its first character.

Return Value

The zero-based character index in the specified line.

Exception typeCondition


The value of the lineNum parameter is less than zero.

If the lineNum parameter is negative, GetFirstCharIndexFromLine returns 0. If the lineNum parameter exceeds the number of lines in the control, GetFirstCharIndexFromLine returns -1.


If the lineNumber parameter is greater than the number of lines in the TextBox, GetFirstCharIndexFromLine returns 0.

GetFirstCharIndexFromLine returns the first character index of a physical line. The physical line is the displayed line, not the assigned line. The number of displayed lines can be greater than the number of assigned lines due to word wrap. For example, if you assign two long lines to a RichTextBox control and set Multiline and WordWrap to true, the two long assigned lines result in four physical (or displayed lines).

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

© 2015 Microsoft