L
leway
Unregistered / Unconfirmed
GUEST, unregistred user!
寫了一個組合控件TEditGauge1,該控件由TMaskEdit、TGauge組成。
目前遇到的困難是無法正確實現控件TEditGauge1的onClick事件,我要達到的目的是鼠標無論點到
TMaskEdit區域還是TGauge區域都能響應。請各位幫忙。一下是控件原碼。
unit TEditGauge;
interface
uses
SysUtils, Classes, Controls,Mask,Gauges,ExtCtrls,strUtils;
type
TEditGauge1 = class(TCustomControl)
private
{ Private declarations }
fMaskEdit:TMaskEdit;
fGauge:TGauge;
fminValue,fMaxValue,fValue:integer;
procedure fsetMinValue(n:integer);
procedure fsetmaxValue(n:integer);
procedure fsetValue(n:integer);
procedure fMaskEditChange(Sender:TObject);
protected
{ Protected declarations }
procedure Click;override;
public
{ Public declarations }
constructor create(AOwner:TComponent);override;
published
{ Published declarations }
property MinValue:integer read fminValue write fSetMinValue;
property MaxValue:integer read fMaxValue write fSetMaxValue;
property Value:integer read fValue write fSetValue;
property OnClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TEditGauge1]);
end;
constructor TEditGauge1.create(AOwner:TComponent);
begin
inherited;
setBounds(0,0,160,20);
fMinValue:=0;
fMaxValue:=100;
fValue:=50;
//create MaskEdit;
fMaskEdit:=TMaskEdit.Create(self);
//fMaskEdit.EditMask:='0000';
fMaskEdit.Text:='50';
fMaskEdit.Left:=0;
fMaskEdit.Top:=0;
fMaskEdit.Width:=32;
fMaskEdit.OnChange:=fMaskEditChange;
fMaskEdit.Anchors:=[akLeft,akTop,akBottom];
fMaskEdit.Parent:=self;
//create gauge
fGauge:=TGauge.Create(self);
fGauge.Parent:=self;
fGauge.Left:=fMaskedit.Width+2;
fGauge.Top:=0;
fGauge.Width:=self.Width-2-fMaskedit.Width-1;
fGauge.Height:=12;
fGauge.Anchors:=[akLeft,akTop,akBottom,akRight];
fGauge.Progress:=50;
end;
procedure TEditGauge1.fsetMinValue(n:integer);
begin
if (fMinValue<>n) and (n<fMaxValue) then
begin
fMinValue:=n;
if n>fValue then
begin
fValue:=n;
fGauge.Progress:=0;
end
else
begin
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
end;
end;
procedure TEditGauge1.fsetmaxValue(n:integer);
begin
if (fMaxValue<>n) and (n>FMinValue) then
begin
fMaxValue:=n;
if n<fValue then
begin
fValue:=n;
fGauge.Progress:=100;
end
else
begin
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
end;
end;
procedure TEditGauge1.fsetValue(n:integer);
begin
if n=fValue then exit;
if (n<fMinValue) or (n>fMaxValue) then exit;
fValue:=n;
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
fMaskEdit.Text:=intToStr(fValue);
end;
procedure TEditGauge1.fMaskEditChange(Sender:TObject);
var
n:integer;
s:string;
begin
s:=fMaskEdit.Text;
s:=ansireplaceText(s,' ','');
n:=strToInt(s);
if (n<fMinValue) or (n>fMaxValue) then exit;
fValue:=n;
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
procedure TEditGauge1.Click;
begin
inherited click;
end;
end.
目前遇到的困難是無法正確實現控件TEditGauge1的onClick事件,我要達到的目的是鼠標無論點到
TMaskEdit區域還是TGauge區域都能響應。請各位幫忙。一下是控件原碼。
unit TEditGauge;
interface
uses
SysUtils, Classes, Controls,Mask,Gauges,ExtCtrls,strUtils;
type
TEditGauge1 = class(TCustomControl)
private
{ Private declarations }
fMaskEdit:TMaskEdit;
fGauge:TGauge;
fminValue,fMaxValue,fValue:integer;
procedure fsetMinValue(n:integer);
procedure fsetmaxValue(n:integer);
procedure fsetValue(n:integer);
procedure fMaskEditChange(Sender:TObject);
protected
{ Protected declarations }
procedure Click;override;
public
{ Public declarations }
constructor create(AOwner:TComponent);override;
published
{ Published declarations }
property MinValue:integer read fminValue write fSetMinValue;
property MaxValue:integer read fMaxValue write fSetMaxValue;
property Value:integer read fValue write fSetValue;
property OnClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TEditGauge1]);
end;
constructor TEditGauge1.create(AOwner:TComponent);
begin
inherited;
setBounds(0,0,160,20);
fMinValue:=0;
fMaxValue:=100;
fValue:=50;
//create MaskEdit;
fMaskEdit:=TMaskEdit.Create(self);
//fMaskEdit.EditMask:='0000';
fMaskEdit.Text:='50';
fMaskEdit.Left:=0;
fMaskEdit.Top:=0;
fMaskEdit.Width:=32;
fMaskEdit.OnChange:=fMaskEditChange;
fMaskEdit.Anchors:=[akLeft,akTop,akBottom];
fMaskEdit.Parent:=self;
//create gauge
fGauge:=TGauge.Create(self);
fGauge.Parent:=self;
fGauge.Left:=fMaskedit.Width+2;
fGauge.Top:=0;
fGauge.Width:=self.Width-2-fMaskedit.Width-1;
fGauge.Height:=12;
fGauge.Anchors:=[akLeft,akTop,akBottom,akRight];
fGauge.Progress:=50;
end;
procedure TEditGauge1.fsetMinValue(n:integer);
begin
if (fMinValue<>n) and (n<fMaxValue) then
begin
fMinValue:=n;
if n>fValue then
begin
fValue:=n;
fGauge.Progress:=0;
end
else
begin
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
end;
end;
procedure TEditGauge1.fsetmaxValue(n:integer);
begin
if (fMaxValue<>n) and (n>FMinValue) then
begin
fMaxValue:=n;
if n<fValue then
begin
fValue:=n;
fGauge.Progress:=100;
end
else
begin
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
end;
end;
procedure TEditGauge1.fsetValue(n:integer);
begin
if n=fValue then exit;
if (n<fMinValue) or (n>fMaxValue) then exit;
fValue:=n;
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
fMaskEdit.Text:=intToStr(fValue);
end;
procedure TEditGauge1.fMaskEditChange(Sender:TObject);
var
n:integer;
s:string;
begin
s:=fMaskEdit.Text;
s:=ansireplaceText(s,' ','');
n:=strToInt(s);
if (n<fMinValue) or (n>fMaxValue) then exit;
fValue:=n;
fGauge.Progress:=((fValue-fMinValue)*100) div (fMaxValue-fMinValue);
end;
procedure TEditGauge1.Click;
begin
inherited click;
end;
end.