首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi 开发复合控件,设计期时不响应鼠标点击选中和拖动。该怎么处理

2012-05-21 
delphi 开发复合控件,设计期时不响应鼠标点击选中和拖动。以下是全部代码各位帮忙看看是不是哪里出错了或者

delphi 开发复合控件,设计期时不响应鼠标点击选中和拖动。
以下是全部代码各位帮忙看看是不是哪里出错了或者还要设置什么地方。
unit NumEdit;

interface

uses
  SysUtils, Classes, Controls,StdCtrls,Messages,Graphics;

type
  TNumEdit = class(TWinControl)
  private
  { Private declarations }
  FEdit:TEdit;
  FLabel:TLabel; 
  FText:string;
  FCaption:string;
// FTransparent:Boolean;
  procedure FSetText(AValue:string);
  function FGetText:string;
  procedure FSetCaption(AValue:string);
  function FGetCaption:string;
  procedure OnEditExit(Sender:TObject);
  procedure onLabelDblClick(Sender:TObject);
// procedure FSetTransparent(AValue:Boolean);
// function FGetTransparent:Boolean;
  function GetonClick: TNotifyEvent;
  procedure SetonClick(const Value: TNotifyEvent);
  protected
  { Protected declarations }
  procedure WMSize(var Msg:TMessage);message WM_SIZE;
  public
  { Public declarations }
  constructor Create(AOwner:TComponent);override;
  destructor Destroy;override;
  published
  { Published declarations }
  property Text:string read FText write FSetText;
  property Caption:String read FCaption write FSetCaption;
  property onClick:TNotifyEvent read GetonClick write SetonClick;
// property onChange:TNotifyEvent read FonChange write FonChange;

  property onEnter;
  property onMouseDown;
  property Color;
  property Font;
  property Width;
  property Height;
  property Top;
  property Left;
  property AutoSize;
  property Align;
// property Alignment;
// property Transparent:Boolean read FTransparent write FSetTransparent;
  property Visible;
  property Tag;
  property onMouseMove;  


  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TNumEdit]);
end;

{ TNumEdit }

constructor TNumEdit.Create(AOwner: TComponent);
begin
  inherited;
  Height:=21;
  Width:=121;
  FEdit:=TEdit.Create(nil);
  FEdit.Parent:=Self;
  FEdit.Top:=0;
  FEdit.Left:=0;
  FEdit.Height:=Height;
  FEdit.Width:=Width;
  FEdit.OnExit:=OnEditExit; 
  FEdit.Visible:=False;
  FEdit.Text:=ClassName;
  FLabel:=TLabel.Create(nil);
  FLabel.Parent:=Self;
  FLabel.Top:=0;
  FLabel.Left:=0;
  FLabel.Height:=Height;
  FLabel.Width:=Width;
  FLabel.OnDblClick:=onLabelDblClick;
  FLabel.Color:=clOlive;
  FLabel.Caption:=ClassName; 
  FLabel.AutoSize:=True;
  FLabel.BringToFront;

end;

destructor TNumEdit.Destroy;
begin
  FEdit.Free;
  FLabel.Free;
  inherited;
end;

procedure TNumEdit.FSetText(AValue: string);
begin
  FEdit.Text:=AValue;
end;

procedure TNumEdit.onLabelDblClick(Sender: TObject);
begin
  FEdit.Visible:=True;
  FEdit.Ctl3D:=False;
  FEdit.Width:=FLabel.Width;
  FEdit.Height:=FLabel.Height;
  FEdit.SetFocus;
end;

procedure TNumEdit.OnEditExit(Sender: TObject);
begin
  FLabel.Caption:=FEdit.Text;
  FEdit.Visible:=False;
end;

procedure TNumEdit.WMSize(var Msg: TMessage);
begin
  FEdit.Top:=0;
  FEdit.Left:=0;
  FEdit.Height:=Height;


  FEdit.Width:=Width;
  FLabel.Top:=0;
  FLabel.Left:=0;
  FLabel.Height:=Height;
  FLabel.Width:=Width;
end;

function TNumEdit.FGetText: string;
begin
Result:=FGetText;
end;

procedure TNumEdit.FSetCaption(AValue: string);
begin
  FLabel.Caption:=AValue;
end;
 
function TNumEdit.FGetCaption: string;
begin
  Result:=FGetCaption;
end;

//function TNumEdit.FGetTransparent: Boolean;
//begin
//Result:=FGetTransparent;
//end;
//
//procedure TNumEdit.FSetTransparent(AValue: Boolean);
//begin
// FLabel.Transparent:=AValue;
//end;

function TNumEdit.GetonClick: TNotifyEvent;
begin
Result:=FLabel.OnClick;
end;

procedure TNumEdit.SetonClick(const Value: TNotifyEvent);
begin
  FLabel.OnClick:=Value;
  FEdit.OnClick:=Value;
end;

[解决办法]
应该是要把label和edit鼠标事件,转给NumEdit本身
[解决办法]
没有重画事件.

热点排行