This documentation is archived and is not being maintained.

TextBox.GetLineText Method

Returns the text that is currently displayed on a specified line.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)

public string GetLineText (
	int lineIndex
)
public String GetLineText (
	int lineIndex
)
public function GetLineText (
	lineIndex : int
) : String
You cannot use methods in XAML.

Parameters

lineIndex

Zero-based line index for which to retrieve the currently displayed text.

Return Value

A string containing a copy of the text currently visible on the specified line.

This example shows how to get a collection of lines of text from a TextBox.

The following example shows a simple method that takes a TextBox as the argument, and returns a StringCollection containing the lines of text in the TextBox. The LineCount property is used to determine how many lines are currently in the TextBox, and the GetLineText method is then used to extract each line and add it to the collection of lines.

StringCollection GetLinesCollectionFromTextBox(TextBox textBox)
{
    StringCollection lines = new StringCollection();

    // lineCount may be -1 if TextBox layout info is not up-to-date.
    int lineCount = textBox.LineCount;

    for (int line = 0; line < lineCount; line++)
        // GetLineText takes a zero-based line index.
        lines.Add(textBox.GetLineText(line));

    return 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
Show: