如何在Delphi中的字符串中添加换行符? [英] How do I include a newline character in a string in Delphi?

查看:950
本文介绍了如何在Delphi中的字符串中添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个跨多行的字符串来分配给标签标题属性。如何在Delphi中完成?

解决方案

在System.pas(自动使用)中定义了以下内容: p>

  const 
sLineBreak = {$ IFDEF LINUX} AnsiChar(#10){$ ENDIF}
{$ IFDEF MSWINDOWS} AnsiString(#13#10){$ ENDIF};

这是从Delphi 2009(注意使用AnsiChar和AnsiString)。 (由我添加的换行符)



所以如果你想使你的TLabel换行,确保将AutoSize设置为true,然后使用以下代码: p>

  label1.Caption:='Line one'+ sLineBreak +'Line two'; 

在sLineBreak引入之后,所有版本的Delphi都可以使用,我相信是Delphi 6。 >

I want to create a string that spans multiple lines to assign to a Label Caption property. How is this done in Delphi?

解决方案

In the System.pas (which automatically gets used) the following is defined:

const
  sLineBreak = {$IFDEF LINUX} AnsiChar(#10) {$ENDIF} 
               {$IFDEF MSWINDOWS} AnsiString(#13#10) {$ENDIF};

This is from Delphi 2009 (notice the use of AnsiChar and AnsiString). (Line wrap added by me.)

So if you want to make your TLabel wrap, make sure AutoSize is set to true, and then use the following code:

label1.Caption := 'Line one'+sLineBreak+'Line two';

Works in all versions of Delphi since sLineBreak was introduced, which I believe was Delphi 6.

这篇关于如何在Delphi中的字符串中添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆