String.Format and a new line

R

rodchar

hey all,
i thought i remember the following working for a new line:
tooltip.text = String.Format("{0}\n{1}"
anybody remember?

thanks,
rodchar
 
M

Michael A. Covington

rodchar said:
hey all,
i thought i remember the following working for a new line:
tooltip.text = String.Format("{0}\n{1}"
anybody remember?

In messageboxes and some other places (maybe including this one) you need
\r\n .
 
D

DH

rodchar said:
hey all,
i thought i remember the following working for a new line:
tooltip.text = String.Format("{0}\n{1}"
anybody remember?

thanks,
rodchar

Use the Environment.NewLine to ensure that a new line is generated
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,
hey all,
i thought i remember the following working for a new line:
tooltip.text = String.Format("{0}\n{1}"
anybody remember?

You have Environment.NewLine just for that.
 
Z

zacks

hey all,
i thought i remember the following working for a new line:
tooltip.text = String.Format("{0}\n{1}"
anybody remember?

That works for me for messages that will be displayed in a message
box, but you may need to use "\r" for a newline in a text file.
 
R

rodchar

man, what is going on?

e.ToolTip = String.Format("{0:N2}{1}{2:c}",
drv["weekPct"], Environment.NewLine, drv["weekAmount"]);

the preceding doesn't work for me.
 
J

Jeff Johnson

man, what is going on?

e.ToolTip = String.Format("{0:N2}{1}{2:c}",
drv["weekPct"], Environment.NewLine,
drv["weekAmount"]);

the preceding doesn't work for me.

Unless there's a special tooltip in .NET, the standard Windows tooltip does
not support line breaks, so you can put in all the CR/LFs your heart desires
and you won't see anything. Somebody correct me if I'm wrong.
 
J

Jeff Johnson

There is a class, System.Windows.Forms.ToolTip, that specifically says you
can specify line breaks with "\r\n". But, we have no idea whether that's
the class you're using. Even your own posts show two completely different
ways of setting the text, neither of which include enough information for
anyone to know what classes you're actually using.

Support for newlines in text is going to be very dependent on the specific
class you're using. Unless you provide full context (e.g. a
concise-but-complete code sample that reliably demonstrates the problem),
your question cannot be answered.

Since he asked "does it matter if it's an asp.net page?" I would assume that
it IS a Web app and the tooltip is going to be generated by the browser,
which means it'll probably be a standard Windows tooltip and therefore not
support line breaks. But yes, that's just a guess and the supplied info is
incomplete.
 
J

Jeff Johnson

Unless there's a special tooltip in .NET

Ah, I see that yes, the Windows Forms tooltip can handle this, mainly
because it encapsulates the newer "balloon" tooltips.
 
R

rodchar

thanks everyone for the help,
rod.

Jeff Johnson said:
Ah, I see that yes, the Windows Forms tooltip can handle this, mainly
because it encapsulates the newer "balloon" tooltips.
 
R

rodchar

I'd like to retract my last reply if I may...
Turns out IE respects the "\n" and FireFox doesn't.

Thank you and good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top