Take the 2-minute tour ×

I have a calculator and want to have exactly 3 lines in my textbox. First line will be number A, second operator and third will be number 2. Now I am using just one line for my application. Can somebody show me how to do that? And I also need to know how CLEAR ONLY first line for exaple and how TO ADD NEW TEXT for exaple to line second without changing other lines.

share|improve this question
Is this winforms or WPF? –  Anton Semenov Apr 19 '11 at 9:53
add comment

4 Answers

up vote 2 down vote accepted

I would use 3 textboxes on top of each other to do this. In this way you can easily clear the particular line you want to clear.

Of course, the exact way you do this depends on whether you are using silverlight, WPF, Windows Forms, or Asp.net.

But for Silverlight or WPF you'd do something like this:

    <TextBox x:Name="Number1" BorderThickness="0" />
    <TextBox x:Name="Operator" BorderThickness="0" />
    <TextBox x:Name="Number2" BorderThickness="0" />

Setting BorderThickness to 0 effectively removes the borders from the textboxes. You can also set FontSize to a bigger font, and set HorizontalAlinment="Right" for a typical calculator style.

You'd then need an event handler (I'm making assumptions about how you want this to work here), that would respond to the enter key, so that the focus moves to the next textbox.

share|improve this answer
But I want it to looks like a big display. If I will use 3 textboxes under each other ....than u can see the separatiomn line between them. –  Nasgharet Apr 19 '11 at 9:23
You can style the textboxes with Silverlight or WPF. –  Dave Arkell Apr 19 '11 at 9:25
That sounds great....but how to change this style for example to WPF? –  Nasgharet Apr 19 '11 at 9:35
See edited answer. –  Dave Arkell Apr 19 '11 at 10:21
I should say, it's pretty easy to remove borders from any textbox, regardless of whether you use Silverlight, WPF, Winforms, Webforms etc –  Dave Arkell Apr 19 '11 at 15:22
add comment

Out of the box you can have a multiline textbox by setting the Multiline to true, but not a text box with three lines .If you want a textbox with three lines I guess you need to develop a custom control yourself.

share|improve this answer
That is what I... I set if for multiline. I just need to know how clear only one line of this multiline textbox and how to add new text to one line only. –  Nasgharet Apr 19 '11 at 9:27
@Nasghaet - "develop a custom control" with what you need. Your requirements dont come out of the box. –  Sujay Ghosh Apr 19 '11 at 9:53
add comment

This doesn't sound like a very user-friendly interface. You're trying to reinvent the wheel in the world of GUI, but it's never a good idea to do so. Why don't you just use three text boxes, one for each input?

On the technical side, in order to create a multi-line text box, you have to set its MultiLine property to true. And then you can split the text into lines using Environment.NewLine:

textBox.Text = "1" + Environment.NewLine + "+" + Environment.NewLine + "3";
share|improve this answer
@Nasgharet You can modify the borders of the text boxes so that the lines between them are not visible. This is definitely not a reason to replace them with one big text box. –  Ilya Kogan Apr 19 '11 at 18:09
add comment

Why don't you use an Multi Line Textbox (Textarea)? In your application keep an array of strings for individual lines. When displaying concatenate the array and set the text on text area.

share|improve this answer
add comment

Your Answer


