一个问题提到第四次,总计250分了!自制控件如何实现背景透明?有哪位高手可以帮我实现的话,我将把250分一并奉送。比如一个椭圆按钮放在一张图片上它实际上覆盖了一

R

redted

Unregistered / Unconfirmed
GUEST, unregistred user!
一个问题提到第四次,总计250分了!自制控件如何实现背景透明?有哪位高手可以帮我实现的话,我将把250分一并奉送。比如一个椭圆按钮放在一张图片上它实际上覆盖了一个矩形区域?(50分)<br />自制控件如何实现背景透明?比如一个椭圆按钮放在一张图片上它实际上覆盖了一个矩形区域?Cheka可能对我这个问题更明白。
代码如下,有哪位高手可以帮我实现的话,我将把250分一并奉送
uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics, Forms,
Dialogs, Buttons, ExtCtrls;

type
TddgButtonEdit = class(TWinControl)
private
{ Private declarations }
FShape1:TShape;
FShape2:TShape;
FLabel:TLabel;
protected
{ Protected declarations }
procedure WMSize(var Message:TWMSize);message WM_SIZE;
procedure SetCaption(Value:String);
function GetCaption:String;
function GetFont:TFont;
procedure SetFont(Value:TFont);
function GetOnLabelClick:TNotifyEvent;
procedure SetOnLabelClick(Value:TNotifyEvent);
public
{ Public declarations }
Constructor Create(AOWner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
Property Caption:String read GetCaption Write SetCaption;
property Font:TFont read GetFont Write SetFont;
Property OnClick:TNotifyEvent read GetOnLabelClick Write SetOnLabelClick;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TddgButtonEdit]);
end;

procedure TddgButtonEdit.WMSize(var Message:TWMSize);
begin
inherited;
FShape2.Width:=Message.Width-2;
FShape2.Height:=Message.Height-4;
FShape2.left:=Message.Width-FShape2.Width;
FShape2.Top:=Message.Height-FShape2.Height;
FShape1.Left:=FShape2.Left-2;
FShape1.top:=FShape2.top-4;
end;

Constructor TddgButtonEdit.Create(AOWner:TComponent);
begin
inherited Create(AOWner);

FShape2:=TShape.create(self);
FShape2.Height:=42;
FShape2.Width:=77;
FShape2.Parent:=self;
FShape2.shape:=stEllipse;
FShape2.brush.Color:=clBlack;

FShape1:=TShape.create(self);
FShape1.Height:= FShape2.Height;
FShape1.Width:= FShape2.Width;
FShape1.Parent:=self;
FShape1.shape:=stEllipse;
FShape1.brush.Color:=clRed;

FLabel:=TLabel.Create(self);
FLabel.Left:=FShape1.Left+3;
FLabel.top:=FShape1.top+7;
FLabel.Height:=29;
FLabel.Width:=72;
FLabel.Height:=29;
FLabel.Width:=57;
FLabel.Alignment:=taCenter;
FLabel.AutoSize:=False;
FLabel.Parent:=self;
FLabel.Transparent:=true;
FLabel.Caption:='ColorButton';
FLabel.Font.Charset:=GB2312_CHARSET;
FLabel.Font.Size:=10;

Width:=FShape2.Width+2;
Height:=FShape2.height+4;

end;

destructor TddgButtonEdit.destroy;
begin
FShape1.free;
FShape2.free;
FLabel.Free;
inherited destroy;
end;

function TddgButtonEdit.GetCaption:String;
begin
Result:=FLabel.Caption;
end;

procedure TddgButtonEdit.SetCaption(Value:String);
begin
FLabel.Caption:=Value;
end;

function TddgButtonEdit.GetFont:TFont;
begin
Result:=FLabel.Font;
end;

procedure TddgButtonEdit.SetFont(Value:TFont);
begin
if Assigned(FLabel.Font) then
FLabel.Font.Assign(Value);
end;

function TddgButtonEdit.GetOnLabelClick:TNotifyEvent;
begin
Result:=FLabel.OnClick;
end;

procedure TddgButtonEdit.SetOnLabelClick(Value:TNotifyEvent);
begin
FLabel.OnClick:=Value;
end;

end.
 
不是很明白你的意思。你是想整個按鈕透明還是只是邊緣部分透明﹖
 
当然是边缘部分啊,如果把它放在一张图片上你就会看到矩形内部椭圆外部部分是灰色的
覆盖了图片
 
老大,你去拆开label的代码看看不行啊?应该不难的。
 
这个问题并不难呀,你应该有两种做法:
1、从TShape类(本身就是透明的)继承,然后模拟Button动作;
2、从TWinControl类继承,然后让它透明。
从某种意义上来说,第一种做法应该是比较好的,我这里有一个透明Button的控件,
如果你需要的话,可以向我索取(liujingnan@netease.com),研究一下它就可以了。
 
从TGraphicControl继承,背景就可以象TLabel一样透明
 
哈哈,这个问题我上周六已解决,我仍从从TWinControl类继承,应该说不是很复杂,但各位
都不能得分,因为有些事情说起来简单,但实现起来很难,虽然只加了两行代码,但一般意义
上的高手是不可能给出来的。
  这个问题到此结束!
 
用连界设置函数,就象做不规则形状的窗体一样。在控件创建的时间定义它的办界就好了
 
var
hr :THandle;
begin
hr:=createroundrectrgn(0,0,width,height,20,20);
SetWindowRgn(Handle,hr,True);
deleteobject(hr);
end;
 
对 redted 这种恶劣的态度我相信大家以后都不会回答他的问题? 大家应当在一起学习
提高,而不是自视甚高,甚至是恶语伤人.............
 
同意楼上,强烈谴责楼主
 
简直就是猪!!! 进屠宰场吧。
 
不就是50分吗,至于吗

鄙视你!
 
rgn
区域
 
这个难吗?
把背景拷一份到你控件的Canvas不就行了吗?
自以为是!
 
顶部