换行的Label控件源码,将caption属性作为Tstrings来编辑
unit LabelRustle;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TLabelRustle = class(TCustomLabel)
private
function GetText : TStrings;
procedure SetText(const Value: TStrings);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BiDiMode;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FocusControl;
property Font;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowAccelChar;
property ShowHint;
property Transparent;
property Layout;
property Visible;
property WordWrap;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property Caption: TStrings read GetText write SetText;
{ Published declarations }
end;
procedure Register;
implementation
function TLabelRustle.GetText:TStrings;
var
Len: Integer;
Temp : TCaption;
begin
Len := GetTextLen;
SetString(Temp, PChar(nil), Len);
if Len <> 0 then GetTextBuf(Pointer(Temp), Len + 1);
Result := TStringList.Create();
Result.SetText(PChar(Temp));
end;
procedure TLabelRustle.SetText(const Value: TStrings);
var
Temp: TCaption;
begin
Temp:=Value.Text;
if GetText <> Value then SetTextBuf(PChar(Temp));
end;
procedure Register;
begin
RegisterComponents('MyComponent', [TLabelRustle]);
end;
end.