Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-get-a-collection-of-lines-from-a-textbox.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

21 lines
1.2 KiB
Markdown

---
title: "How to: Get a Collection of Lines from a TextBox"
ms.date: "03/30/2017"
helpviewer_keywords:
- "lines [WPF], getting collection of"
- "TextBox control [WPF], getting collection of lines"
ms.assetid: a12f529d-b926-47f6-92bf-cad5f17b532a
---
# How to: Get a Collection of Lines from a TextBox
This example shows how to get a collection of lines of text from a <xref:System.Windows.Controls.TextBox>.
## Example
The following example shows a simple method that takes a <xref:System.Windows.Controls.TextBox> as the argument, and returns a <xref:System.Collections.Specialized.StringCollection> containing the lines of text in the **TextBox**. The <xref:System.Windows.Controls.TextBox.LineCount%2A> property is used to determine how many lines are currently in the **TextBox**, and the <xref:System.Windows.Controls.TextBox.GetLineText%2A> method is then used to extract each line and add it to the collection of lines.
[!code-csharp[TextBox_MiscCode#_TextBox_GetLines](~/samples/snippets/csharp/VS_Snippets_Wpf/TextBox_MiscCode/CSharp/Window1.xaml.cs#_textbox_getlines)]
## See also
- [TextBox Overview](textbox-overview.md)
- [RichTextBox Overview](richtextbox-overview.md)