Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TextBox.LineCount Property

Gets the total number of lines in the TextBox.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public int LineCount { get; }
/** @property */
public int get_LineCount ()

public function get LineCount () : int

You cannot use this property in XAML.

Property Value

An integer indicating the total number of lines in the TextBox, or -1 if layout information is not available for the TextBox. This property has no default value.

If text wrapping is enabled, changing the width of the TextBox may change this value.

The value returned is the total number of lines in the TextBox, regardless of how many are currently visible.

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.