关于换行的Caption
总是发现有很多人需要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结束