更改字的顏色要不要
![]()
..不是背景..寫一個小程式你看看...自行修改,
class="code">
unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls; type TCharFormat = record
cbSize: UINT;
dwMask: Longint;
dwEffects: Longint;
yHeight: Longint;
yOffset: Longint;
crTextColor: TColorRef;
bCharSet: Byte;
bPitchAndFamily: Byte;
szFaceName: array[0..LF_FACESIZE - 1] of AnsiChar;
end; TForm1 = class(TForm)
Button1: TButton;
RichEdit1: TRichEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure changecolor(a,b,c:byte);
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.changecolor(a,b,c:byte);
var
CharFormat : TCharFormat;
const EM_GETCHARFORMAT=WM_USER 58;
const EM_SETCHARFORMAT=WM_USER 68; begin
ZeroMemory(@CharFormat, SizeOf(TCharFormat));
with CharFormat do
begin
cbSize := SizeOf(TCharFormat);
{先取得原本char的charfotmat}
RichEdit1.Perform(EM_GETCHARFORMAT, 1, LParam(@CharFormat));
{更改顏色}
crTextColor:=rgb(a,b,c);
RichEdit1.Perform(EM_SETCHARFORMAT, wParam(1), LParam(@CharFormat));
end;
RichEdit1.SetFocus;
RichEdit1.SelLength := 0;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
changecolor(255,44,55);
end; end.
![]()
發表人 -