看来大家都不明白!!! 我要的是控件要拥有此功能(在TDBEdit原有的功能上加一个
功能: 随着用户输入值的变化而用不同的颜色表示), 而不需要用户自己在控件的
onchange 事件写代码,要不还要写这个控件干嘛?!!1
且看我的控件的源代码!! 各位不妨把控件加到delphi里试一试,
unit WarnDBEdit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ADODB,
StdCtrls, Mask, DBCtrls;
type
TWarnDBE = class(TDBEdit)
private
{ Private declarations }
FMYMax:real;
FMYMin:real;
protected
{ Protected declarations }
constructor create(AOwer: TComponent);override;
procedure Change(); override;
public
{ Public declarations }
published
{ Published declarations }
property MaxValues: real read FMYMax write FMYMax ;
property MinValues: real read FMYMin write FMYMin ;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TWarnDBE]);
end;
constructor TWarnDBE.create(AOwer: TComponent);
begin
inherited;
end;
procedure TWarnDBE.Change();
var
values,max,min:real;
begin
self.Font.Color:=clWindowText;
try
if self.text='' then
values:=0
else
values:=strtofloat(self.text);
max:=self.MaxValues;
min:=self.MinValues;
if values > Max then
self.Font.Color:= clRed;
if values = Max then
self.Font.Color:= clMaroon;
if values < Min then
self.Font.Color:= clBlue;
if values = Min then
self.Font.Color:= clNavy;
except
end;
end;
end.