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;
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 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); Canvas.Font.Color:=clBlue; Canvas.TextOut(0,0,Text); BitBlt(DC,0,(R.Bottom-abs(Canvas.Font.Height)) div 2, R.Right,R.Bottom,Canvas.Handle,0,0,SrcCopy); Free; end; ReleaseDC(Edit1.Handle,DC); end; procedure TForm1.FormActivate(Sender: TObject); var n:integer; begin for n:=0 to ControlCount-1 do Controls[n].Refresh; end;
var vElements: Integer; vRgbValues: TColor; begin vElements := COLOR_GRAYTEXT; vRgbValues := clBlack; SetSysColors(1, vElements, vRgbValues); end;
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;
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;
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); Canvas.Font.Color:=clBlue;
Canvas.TextOut(0,0,Text); BitBlt(DC,0,(R.Bottom-abs(Canvas.Font.Height)) div 2,
R.Right,R.Bottom,Canvas.Handle,0,0,SrcCopy); Free;
end;
ReleaseDC(Edit1.Handle,DC);
end; procedure TForm1.FormActivate(Sender: TObject);
var
n:integer;
begin
for n:=0 to ControlCount-1 do
Controls[n].Refresh;
end;
vElements: Integer;
vRgbValues: TColor;
begin
vElements := COLOR_GRAYTEXT;
vRgbValues := clBlack;
SetSysColors(1, vElements, vRgbValues);
end;
>>>那还不如用个panel来为装... 呵