关于换行的Caption

Kingron 2002-07-31 08:48:26
总是发现有很多人需要Caption之类的能够换行,大多数人是采取写代码的方式,例如:Label1.Caption:='A'#13'B'#13'C'#13'D';这样也无可非议,是正确的,但始终是感觉不爽!因此我就写了下面的这个冬冬,安装之后,集成到Delphi开发环境中,以后就不用携带码来换行了,别看代码虽小,可是使用起来可是方便不少啊!

使用方法,把下面的两个文件分别以他们的文件名保存,然后打开StrEditDlg.pas,在Delphi IDE中,选择Component-->Install Component,然后点击OK,Build即可。

///适用于Delphi5和Delphi6。
////StrEditDlg.pas内容如下:
unit StrEditor;

interface

uses Windows,Classes, Controls, StdCtrls,Buttons, TypInfo,Forms,ExtCtrls,{$IFDEF VER140}DesignIntf, VCLEditors
{$ELSE}DsgnIntf{$ENDIF};

type
TStrEditDlg = class(TForm)
Memo: TMemo;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Bevel1: TBevel;
BitBtn3: TBitBtn;
procedure BitBtn3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

type
TCaptionEditor = class(TCaptionProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;

procedure Register;

implementation

{$R *.DFM}

procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Caption', TCaptionEditor);
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Text', TCaptionEditor);
end;

{ THintProperty }

procedure TCaptionEditor.Edit;
var
Temp : string;
Comp : TPersistent;
I, Cnt : Integer;
begin
with TStrEditDlg.Create(Application) do
try
Comp := GetComponent(0);
if Comp is TComponent then
Caption := TComponent(Comp).Name + '.' + GetName
else
Caption := GetName;
Memo.Text :=GetStrValue;
if ShowModal = mrOk then
SetStrValue(Memo.Text);
finally
Free;
end;
end;

function TCaptionEditor.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;

procedure TStrEditDlg.BitBtn3Click(Sender: TObject);
begin
MessageBox(Handle,'Copyright (C) Kingron 2002','Info',MB_OK+MB_ICONINFORMATION);
end;

end.

/////StrEditDlg.pas结束

////StrEditDlg.DFM开始
object StrEditDlg: TStrEditDlg
Left = 283
Top = 106
BorderStyle = bsDialog
Caption = 'Caption Editor'
ClientHeight = 221
ClientWidth = 347
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 8
Top = 11
Width = 329
Height = 161
Shape = bsFrame
end
object Memo: TMemo
Left = 16
Top = 24
Width = 313
Height = 137
TabOrder = 0
end
object BitBtn1: TBitBtn
Left = 176
Top = 189
Width = 75
Height = 25
Caption = '&OK'
TabOrder = 1
Kind = bkOK
end
object BitBtn2: TBitBtn
Left = 264
Top = 189
Width = 75
Height = 25
Caption = '&Cancel'
TabOrder = 2
Kind = bkCancel
end
object BitBtn3: TBitBtn
Left = 8
Top = 188
Width = 75
Height = 25
Caption = '&About'
TabOrder = 3
OnClick = BitBtn3Click
Kind = bkHelp
end
end
////StrEditDlg.DFM结束
...全文
551 32 打赏 收藏 转发到动态 举报
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
Henc 2002-08-02
  • 打赏
  • 举报
回复
果然是好东西!我要收藏!
Billy_Chen28 2002-08-02
  • 打赏
  • 举报
回复
+1
dongxsoft 2002-08-02
  • 打赏
  • 举报
回复
我顺便问一下:如何让QRDBText自动换行?
dreamfan 2002-08-02
  • 打赏
  • 举报
回复
不错,谢谢先
CXZ9 2002-08-02
  • 打赏
  • 举报
回复
能让DBGrid的Title换行吗?
我要多行的。
用'abc'#13'dfg'
不行的。那样只是中间多了个空格
============================
@* .☆ / */ . / * . ☆/ *。
◢◣。 ◢◣。
◢★◣。 ◢★◣。
◢■■◣。 ◢■■◣。
◢■■■◣。 ◢■■■◣。
︸︸||︸︸ !!︸︸||︸︸
愿您有快乐的每一天 ^_^!!
ybli 2002-08-02
  • 打赏
  • 举报
回复
到处都是星!
不过Kingron(单身走我路……)与 zswang(伴水)(努力工作中)我还是比较佩服
的,曾经帮我解决不少问题,在此表示感谢
王集鹄 2002-08-01
  • 打赏
  • 举报
回复
一般我是通过修改窗体代码来实现
object Label1: TLabel
Left = 120
Top = 136
Width = 26
Height = 65
Caption = 'Line1'#13#10'Line2'#13#10'Line3'#13#10'Line4'#13#10
end


嘻嘻嘻 有总比没有好! 嘻嘻嘻嘻
日总是我哥 2002-08-01
  • 打赏
  • 举报
回复

用ed~~
naughtyboy 2002-08-01
  • 打赏
  • 举报
回复
top
日总是我哥 2002-08-01
  • 打赏
  • 举报
回复

呵呵 :-)
Kingron 2002-08-01
  • 打赏
  • 举报
回复
Flashman,你这个方法早就用过了,不是不知道,而是嫌麻烦!而且没有了AutoSize功能!
guguda 2002-08-01
  • 打赏
  • 举报
回复
好,好,学习。
lyhold 2002-08-01
  • 打赏
  • 举报
回复
但是还是要感谢楼主!!
flashman 2002-08-01
  • 打赏
  • 举报
回复
再 续上。

希望我能和你们交个朋友。我的QQ是:5980274 同样是不变的: flashman
flashman 2002-08-01
  • 打赏
  • 举报
回复
续上

我来告诉你们吧。
将 Label 的 AutoSize 设置为 False
WordWrap 设置为 True
这样就可以了,你们试试吧。

有一个窍门:你先设置好宽度,然后在你要换行的字母或者汉字前加一些空格,就可以达到你所要的目的了。

Use you head ! Delphi 一这么优秀的开发工具 连你能够想到的这点也做不到那还有什么用, VC++ 就很弱智,不但这点做不到,连设置字体和颜色都做不到。 I like & love Delphi
flashman 2002-08-01
  • 打赏
  • 举报
回复
笨蛋,都是笨笨。 Label的Caption 是可以设置属性来达到换行的目的的。
dext 2002-08-01
  • 打赏
  • 举报
回复
谢谢,先!
jerrymousenet2 2002-08-01
  • 打赏
  • 举报
回复
多谢了。
hfkobe 2002-07-31
  • 打赏
  • 举报
回复
谢谢!
我正用得着!
santwy 2002-07-31
  • 打赏
  • 举报
回复
你们是星级人物野
加载更多回复(12)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧