你可以使用int SetBkMode(
HDC hdc, // handle to DC
int iBkMode // background mode
);将你绘图窗口DC的iBkMode设置成iBkMode 也可以将你的前景色设置成和字体一样的颜色
HDC hdc, // handle to DC
int iBkMode // background mode
);将你绘图窗口DC的iBkMode设置成iBkMode 也可以将你的前景色设置成和字体一样的颜色
2.用label,不用canvas.textout
3.Specifies how text is written to the canvas. property TextFlags: LongInt;DescriptionUse TextFlags to influence the way text is drawn when calling the TextOut or TextRect method. TextFlags is an integer made by combining any of the following constants:
在窗口中采用Canvas.TextOut来输出显示文本,要使其背景成为透明的,那么要先添加一句: SetBkMode(Canvas.Handle,TRANSPARENT);
OK?
首先将菜单的ownerdraw属性设置为true;然后在菜单项的drawitem中写入代码即可。
procedure TForm1.New1DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
begin
acanvas.Font.Color:=clred;
if selected then //如果选择了
SetBkColor(acanvas.handle,clgreen) //那么设置背景色
else
setBkcolor(acanvas.handle,clblue); //否则设置为原来的颜色
acanvas.TextRect(arect,0,0,new1.caption); //输出菜单文字
end;
设置Canvas.Brush.Color跟前景色一样就可以了:
canvas.Brush.Color:=clred;//设置背景色为红色!
canvas.TextOut(20,20,'fskfsff'); //输出红底的字符!给分吧。
我想要一本杂志。
我发现了一个慢但实用方法,用BITMAP写字,取他的MASK,再将透明设为true,再用CANVAS.DRAW画上去,大家有好的方法,快讲!
// 背景图中有文字的部分处理为“透明色”
TxtImg.Transparent := true;
TxtImg.TransparentMode := tmFixed;
TxtImg.TransparentColor := $1000000;
with TxtImg.Canvas do
begin
Brush.Color := $1000000; // 文字的背景色
Brush.Style := bsClear;
Rectangle(0, 0, MaxInt, MaxInt);
Font.Color := FontColor; // 文字前景色
TextOut(x, y, TextStr);
end;btw: canvas.brush.bitmap:=bitmap;会有问题的,应:canvas.brush.bitmap.assign(bitmap);
你试试这个思路: 新建一个TLabel类的Mylab,设置其Transparent的属性为True,然后设置其Caption的值为你想要显示的字,这个方法行得通。procedure DisplayText;
var MyLab:TLabel;
begin
MyLab:=Tlabel.Create(self);
Mylab.Parent := Form1;
mylab.Transparent:=true;
mylab.Caption:='哦,真的可以呀~';
mylab.Left:=40;
mylab.Top:=40;
end;
在canvas.textout('abcdde');
前加上一句
Canvas.Brush.Style := bsClear;
It's OK ?