---
title: "Multiline issue WPF TextBox"  
description: "Multiline issue WPF TextBox"  
author: "Anonymous User"  
published: 2013-09-03  
updated: 2013-09-03  
canonical: https://www.mindstick.com/forum/1423/multiline-issue-wpf-textbox  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# Multiline issue WPF TextBox

I creating [multiline](https://www.mindstick.com/interview/103/what-s-the-difference-between-comments-comments-and-comments) [TextBox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) with this [Link](https://www.mindstick.com/articles/23633/link-builder) its work better but if I want to set TextBox [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) [counter](https://www.mindstick.com/interview/33859/how-to-create-pixel-counter-in-javascipt)

label1.Content = textBox1.Text.Length;

with above line work fine but [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) is that when I press enter in the TextBox counter it will [increase](https://www.mindstick.com/articles/12959/are-you-struggling-to-increase-the-profit-of-your-liquor-store) 2 [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) in TextBox counter.

How can I do this [task](https://www.mindstick.com/forum/161761/what-is-the-difference-between-task-and-thread) please help me.

Any help appreciated!

## Replies

### Reply by Sumit Kesarwani

Hi John,\

If you need just one character on "Enter" then you can just handle PreviewKeyDown event on TextBox and paste following handler:

```
    private void Txt_OnPreviewKeyDown(object sender, KeyEventArgs e)    {        if (e.Key == Key.Enter)        {            var txtBox = e.Source as TextBox;            var selectionStart = txtBox.SelectionStart;            txtBox.Text = txtBox.Text.Insert(selectionStart, "\n");            txtBox.Select(selectionStart + 1, 0);            e.Handled = true;         }    }
```


---

Original Source: https://www.mindstick.com/forum/1423/multiline-issue-wpf-textbox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
