procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Enabled:=False;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
text:string;
DC:HDC;
R:TRect;
begin
Text:='我测试';
R:=Edit1.ClientRect;
DC:=GetDC(Edit1.Handle);
with TBitmap.Create do
begin
Width:=R.Right;
Height:=R.Bottom;
Canvas.Brush.Color:=Edit1.Color;
Canvas.FillRect(R);
procedure TForm1.Button1Click(Sender: TObject);
var ec:Tcanvas;
begin
try
ec:=Tcanvas.Create;
ec.Handle:=Getdc(edit1.Handle);
if ColorDialog1.Execute then
ec.Font.Color:=ColorDialog1.Color;
ec.TextOut(1,1,edit1.Text);
finally
ec.free;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Enabled:=false;
Edit1.Text:='让不可用的Edit内容显示任意颜色';
Button1.Caption:='Color';
end;
procedure EnableControl(AControl: TWinControl; Enable: Boolean);
begin
with AControl do
if Enable then
SetWindowLong(Handle, GWL_STYLE, (not WS_DISABLED) and GetWindowLong(Handle, GWL_STYLE))
else
SetWindowLong(Handle, GWL_STYLE, WS_DISABLED + GetWindowLong(Handle, GWL_STYLE));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnableControl(Edit1,False);
end;