我把川中小马的程序改了改,又发现新的问题:
unit MJSBtn;
interface
uses
SysUtils, Classes, Controls, Types, Graphics, Messages,ExtCtrls;
type
TMJSBtn = class(TCustomControl)
private
{ Private declarations }
protected
{ Protected declarations }
public
procedure paint; override;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure WMLBUTTONDOWN(var Message: TMessage); message WM_LBUTTONDOWN;
procedure WMLBUTTONUP(var Message: TMessage); message WM_LBUTTONUP;
{ Public declarations }
published
property Caption;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('xhh', [TMJSBtn]);
end;
{ TMJSBtn }
procedure TMJSBtn.CMTextChanged(var Message: TMessage);
begin
repaint;
end;
procedure TMJSBtn.Paint;
var
MainRect,rec : TRect;
begin
inherited;
with Canvas do
begin
Brush.Color := clBtnFace;
MainRect:=ClientRect;
frame3D(Canvas,MainRect,clBtnHighlight,clBtnShadow,2);
if Caption <> '' then
begin
TextOut(10, 10, Caption);
Rec.Left := Width - 10;
rec.Top := 10;
rec.Right := 2;
rec.Bottom := Height - 10;
DrawFocusRect(rec);
end;
end;
end;
procedure TMJSBtn.WMLBUTTONDOWN(var Message: TMessage);
var
MainRect: TRect;
begin
MainRect:=ClientRect;
frame3D(Canvas,MainRect,clBtnShadow,clBtnHighlight,2);
end;
procedure TMJSBtn.WMLBUTTONUP(var Message: TMessage);
var
MainRect: TRect;
begin
MainRect:=ClientRect;
frame3D(Canvas,MainRect,clBtnHighlight,clBtnShadow,2);
end;
end.
如果连续按这个按钮后,无论鼠标点在form的什么地方,这个按钮都会被按下。这是为什么?要怎么改呢?