473,412 Members | 5,361 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Wrapping label text in C#

Hi,

I am trying to have one label on a form with multi line display of the
results from a database query. so my query looks like

Select FirstName+" "+LastName+"\r\n"+Address as Info

I want to have the label show

FirstName LastName
Address

I thought that \r\n in the returned result will make it happen but
Label shows up as

FirstName LastName\r\nAddress

Anybody knows how the string should e cosntructed so that the label
text is wrapped where is needed?

Thanks

Nov 17 '05 #1
5 9593
If this is for a windows app then \n should work. If this is for the web
use <br>.

--

Derek Davis
dd******@gmail.com

<le******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I am trying to have one label on a form with multi line display of the
results from a database query. so my query looks like

Select FirstName+" "+LastName+"\r\n"+Address as Info

I want to have the label show

FirstName LastName
Address

I thought that \r\n in the returned result will make it happen but
Label shows up as

FirstName LastName\r\nAddress

Anybody knows how the string should e cosntructed so that the label
text is wrapped where is needed?

Thanks

Nov 17 '05 #2
Hi le_mo_mo,
instead of using \r\n use System.Environment.NewLine instead. This will
substitute in the correct newline characters for the system you are running
the code on.

Hope that helps
Mark R Dawson
http://www.markdawson.org

"le******@yahoo.com" wrote:
Hi,

I am trying to have one label on a form with multi line display of the
results from a database query. so my query looks like

Select FirstName+" "+LastName+"\r\n"+Address as Info

I want to have the label show

FirstName LastName
Address

I thought that \r\n in the returned result will make it happen but
Label shows up as

FirstName LastName\r\nAddress

Anybody knows how the string should e cosntructed so that the label
text is wrapped where is needed?

Thanks

Nov 17 '05 #3

For a Web Application, carion1, is correct...use "<BR>"...

for a Windows Application, try (if the \n..doesn't work for you)

Select FirstName + ' ' + LastName + char(10)+char(13) <or is it 13 then
10...double check> + Address as info
--
rviray
------------------------------------------------------------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=4211
View this thread: http://www.msusenet.com/t-1871084823

Nov 17 '05 #4
<le******@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am trying to have one label on a form with multi line display of the
results from a database query. so my query looks like

Select FirstName+" "+LastName+"\r\n"+Address as Info


This would add a literal "\r\n" to the string, which would be the same as
doing:

label1.Text = "Danny\\r\\nTuppeny";

IIRC, you can use linebreaks in SQL, so maybe something like

SELECT FirstName + " " + LastName + "
" + Address as Info

would work?

Alternatively, you could (though it's pretty bad ;)) replace literal \r\n
with real linebreaks:

label1.Text = dr["Info"].Replace("\\r\\n", "\r\n");
Nov 17 '05 #5
I would not recommend writing:
Select FirstName + ' ' + LastName + char(10)+char(13) <or is it 13 then
10...double check> + Address as info
That is not very readable or portable. System.Environment.NewLine should be
used
"rviray" wrote:

For a Web Application, carion1, is correct...use "<BR>"...

for a Windows Application, try (if the \n..doesn't work for you)

Select FirstName + ' ' + LastName + char(10)+char(13) <or is it 13 then
10...double check> + Address as info
--
rviray
------------------------------------------------------------------------
rviray's Profile: http://www.msusenet.com/member.php?userid=4211
View this thread: http://www.msusenet.com/t-1871084823

Nov 17 '05 #6

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

Similar topics

1
by: Buddy | last post by:
Hello, Does anyone know how to stop labels from wrapping text. If the text is to long for the label then I want it to hide the text just like out the TextBox control works. Thanks,
4
by: abc | last post by:
This seems like a stupid question, but I can't find the property to prevent the text in a Label control from wrapping on the next line. Thanks.
4
by: Richard MSL | last post by:
I have an application using WinForms under C#. I do not use the IDE, I use the command line compiler, I build my controls in my application code. The application generally works fine, except for...
7
by: Mike Casey | last post by:
Hello all, I have ASP.NET label controls tied to a datasource (so text will vary in length depending on the record). In IE everything looks great--text is wrapped if needed. In Netscape and...
1
by: mg | last post by:
I set the width of a WebForm Label but do not get line wrapping (see below). What can I do to get line wrapping WebForm1.asp <asp:Labe id="Label1" style="Z-INDEX: 101; LEFT: 40px; POSITION:...
2
by: Amelyan | last post by:
If I have spaces in my Text property of Label, and I add it to TableCell, it wraps at spaces. E.g. Label lb = new Label(); lb.Text = "Hello, World!" TableCell cell = new TableCell();...
1
by: lisa232 | last post by:
Hi All, I have a problem with some javascript code. I am trying to toggle display between two tables upon change of a select box ( to alternate between search forms) eg. one called...
2
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have a label inside an html table cell and was wondering if someone could please show me how to force it to wrap at a certain width? thanks, rodchar
0
by: Kevin McKinley | last post by:
Below i've put the code for a program that i wrote. I need help on lines 384-403. If you run this program you will notice on the first tab when have it produce an answer the $ is surrounded with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.