如何将其透明啊 (100分)

  • 主题发起人 cccccccs
  • 开始时间
C

cccccccs

Unregistered / Unconfirmed
GUEST, unregistred user!
继承的TCustomControl的控件,主要是用
ComRegion:=CreatePolygonRgn(RectPoint,4,ALTERNATE);
SetWindowRgn(Handle,ComRegion,True);
来实现将矩形(当很狭窄时成为直线)作为控件处理
此时有个问题就是,怎么可以将这个控件透明化呢,即当放到面板上时可以看到背景,但是又不能隐藏,各位
帮忙啊
其实也就是怎么怎么画一个透明的矩形
 
用shape画4根线罗
何必如此麻烦。
 
如果不需要容器性能,继承TGraphicControl画。
 
看一下TCustomLable是如何实现透明的
 
用下面的API
int SetBkMode(
HDC hdc, // handle of device context
int iBkMode // flag specifying background mode
);

Parameters
hdc
Handle to the device context.
iBkMode
Specifies the background mode. This parameter can be either of the following values: Value Description
OPAQUE Background is filled with the current background color before the text, hatched brush, or pen is drawn.
TRANSPARENT Background remains untouched.
 
这个API不行啊,只能消去背景

我需要要控件本身透明,也就是画出一个透明的框

另外,就算继承TGraphicControl,又怎么画出一个透明的框来呢

用Shape是不可能的,因为这个框多数情况下是狭窄而倾斜的,就像用canvas的Polygon画出的东西
 
随手写了一个,你参考一下吧。
unit Test;

interface

uses
Windows, Messages, SysUtils, Classes, Controls,Graphics;
type
TTestType = (ttRectangle,ttRoundRect,ttEllipse);

type
TTest = class(TGraphicControl)
private
FType: TTestType;

procedure SetType(Value: TTestType);
protected
procedure Paint;override;
public
constructor Create(AOwner: TComponent);override;
published
property TestType: TTestType read FType write SetType;
end;

procedure Register;

implementation

constructor TTest.Create(AOwner: TComponent);
begin
inherited;
Canvas.Brush.Style := bsClear;
end;

procedure TTest.SetType(Value: TTestType);
begin
if Value <> FType then
begin
FType := Value;
Invalidate;
end;
end;

procedure TTest.Paint;
begin
inherited;
case FType of
ttRectangle:
Canvas.Rectangle(0, 0, Width, Height);
ttRoundRect:
Canvas.RoundRect(0, 0, Width, Height,Width div 2,Height div 2);
ttEllipse:
Canvas.Ellipse(0, 0, Width, Height);
end;
end;

procedure Register;
begin
RegisterComponents('dwh', [TTest]);
end;

end.
 
这影子这个倒是可以实现,不过为什么尽管画出一个斜的四边形,但是点击的时候系统依然认为
这个四边形所在的整个矩形范围都算是该控件呢
 
要重建Region才行的
 
呼呼呼,我也知道要重建

但是怎么建啊,不太会用TGraphicControl啊
 
看看PtInRegion的帮助。
 
因为delphi的可显示控件几乎都是矩形范围的,不管它显示成什么样子

现在的问题是需要让tgraphiccontrol的范围成为一个斜的四边形

用PtInRegion明显不能解决问题啊
555~~~~莫非这个问题就解决不了了吗
 
好象越来越偏离题目了。
上面控件的代码解决了透明的问题;
ptInRegion可以判断是否点击在那个斜四边形内;
现在又需要直接生成一个斜四边形。

白忙一场,搜索一下透明panel,看看有没有帮助。
 
呵呵,还是用ptinregion,然后是的话就触发onclick,否则就跳走
 
顶部