473,513 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on help... And stringing things along...

Ok, either I'm doing something wrong or the filters in help are worthless...

I'm trying to format a string... Nothing special, just formatting... like
C++...

How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";
Nov 15 '05 #1
5 1263

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok, either I'm doing something wrong or the filters in help are worthless...
I'm trying to format a string... Nothing special, just formatting... like
C++...

How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";

Ok... the newline character works in a string... apparently it just doesn't
get displayed in a textbox control...

Anybody have a clue what's going on? I have the textbox Multiline and
acceptsReturn properties set to True. What am I missing?
Nov 15 '05 #2
Chuck Bowling <ch**********@sbcglobal-NO-SPAM.net> wrote:
How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";

Ok... the newline character works in a string... apparently it just doesn't
get displayed in a textbox control...

Anybody have a clue what's going on? I have the textbox Multiline and
acceptsReturn properties set to True. What am I missing?


You need to use \r\n instead of \n between lines. For instance:

using System;
using System.Windows.Forms;
using System.Drawing;

public class Test : Form
{
Test()
{
Size = new Size(200,200);
TextBox tb = new TextBox();
tb.Size = new Size (150, 150);
tb.Text = "First line\nSecond line\r\nThird line";
tb.Multiline = true;
Controls.Add(tb);
}

static void Main()
{
Application.Run(new Test());
}
}

comes up with

First line Second line
Third line

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Great. Thanks for your help Jon..
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Chuck Bowling <ch**********@sbcglobal-NO-SPAM.net> wrote:
How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";

Ok... the newline character works in a string... apparently it just doesn't get displayed in a textbox control...

Anybody have a clue what's going on? I have the textbox Multiline and
acceptsReturn properties set to True. What am I missing?


You need to use \r\n instead of \n between lines. For instance:

using System;
using System.Windows.Forms;
using System.Drawing;

public class Test : Form
{
Test()
{
Size = new Size(200,200);
TextBox tb = new TextBox();
tb.Size = new Size (150, 150);
tb.Text = "First line\nSecond line\r\nThird line";
tb.Multiline = true;
Controls.Add(tb);
}

static void Main()
{
Application.Run(new Test());
}
}

comes up with

First line Second line
Third line

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
There is an
Environment.NewLine Property

Which, in Windows, is equivalent to "\r\n"
It may be different on other platforms, so if you plan on using other
platforms, you may want to use this property instead.

Chris R.

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:#v**************@TK2MSFTNGP10.phx.gbl...
Ok, either I'm doing something wrong or the filters in help are worthless...
I'm trying to format a string... Nothing special, just formatting... like
C++...

How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";

Nov 15 '05 #5
Ok. Thanks Chris...

"Chris R" <so*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
There is an
Environment.NewLine Property

Which, in Windows, is equivalent to "\r\n"
It may be different on other platforms, so if you plan on using other
platforms, you may want to use this property instead.

Chris R.

"Chuck Bowling" <ch**********@sbcglobal-NO-SPAM.net> wrote in message
news:#v**************@TK2MSFTNGP10.phx.gbl...
Ok, either I'm doing something wrong or the filters in help are

worthless...

I'm trying to format a string... Nothing special, just formatting... like C++...

How do I do a newline? i.e., assigning a string to a textbox...

txt.Text = "My first line...\n My second line...\n My third line...";


Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1764
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7" valign="top"><form name="booknow"><select
8
2966
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the value in the text box. I have the following code but when the user enters a decimal value the Regex.IsMatch catches it (ex. 250.50 should be allowed,...
3
1279
by: arthur-e | last post by:
Thanks in advance!! I've looked at fConcatFld but that doesn't seem to be what i'm looking for or I just can't figure it out. I'm trying to have a button select records based on two combo boxes - one holding a number and one text. Floor(combo18) is a floor number and site(combo20) is a building name Private Sub Command22_Click() Dim...
11
1584
by: dhnriverside | last post by:
Hi peeps Ok, so I thought I'd have a go at making a console app in VS2k5... I haven't written any windows apps for years, let alone dos apps (been web programming) and I've hit a dumb error... "An object reference is required for the nonstatic field, method or property " This is occuring in my main function...
3
1654
by: ESmith | last post by:
I have multi-page form where I pass an object between pages as follows: On each page: // What page to go to next private void btnContinue_Click(object sender, System.EventArgs e) { if (Page.IsValid) { MyXferObj obj = new MyXferObj();
1
3694
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am...
6
1671
by: JOSII | last post by:
Getting a string of boolean value into and out of the registry is no problem. Here's the problem: Although you can place an object into the registry and retreive it, I need to place an ArrayList object with 10 string items into the registry and retreive them later. I tried this: key.SetValue("lstNSXitems", lstNSX.Items) where...
0
5522
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
2
2005
by: abdiphp | last post by:
Hi every one, I need help to get the this going, Itried whatever I can but could not get the right xpath to this xml I need to get the value of this node (IMAGE_FILE) and this is not working /row/ARTICLE/RELATE/IMAGE_FILE/IMAGE_PATH
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7563
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4757
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.