半透明Panel控件问题
来源:互联网 发布:淘宝上哪个符点是真的 编辑:程序博客网 时间:2024/05/18 02:59
unit TransPanel;interfaceuses Windows, Messages, SysUtils, Classes, Controls, Forms, Graphics, StdCtrls;type TBlendValue = 0..100; TTransPanel = class(TCustomcontrol) private Fborder: Boolean; FAlignment: TAlignment; FBlendValue: TBlendValue; FColor:TColor; procedure Setborder(Value: Boolean); procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND; procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING; procedure SetAlignment(const Value: TAlignment); procedure SetBlendValue(const Value: TBlendValue); procedure SetColor(Value: TColor); protected Buffer: TBitmap; procedure Paint; override; public procedure CreateParams(var Params: TCreateParams); override; constructor Create(AOwner: TComponent); override; destructor Destroy; override; published property Alignment: TAlignment read FAlignment write SetAlignment default taCenter; property Anchors; property Border: Boolean read Fborder write Setborder; property Color: TColor read FColor write SetColor; property BlendValue: TBlendValue read FBlendValue write SetBlendValue; property Caption; property Font; property Visible; property Enabled; property Align; property OnClick; property OnMouseDown; property OnMouseMove; property OnMouseUp; end;procedure Register;implementation{TTransPanel }procedure Register;begin RegisterComponents('Touchbook', [TTransPanel]);end;constructor TTransPanel.Create(AOwner: TComponent);begin inherited Create(AOwner); Buffer := TBitmap.Create; Width := 185; Height := 41; FAlignment := taCenter; Color:=clBtnFace; BlendValue:=50;end;destructor TTransPanel.Destroy;begin Buffer.Free; inherited Destroy;end;procedure TTransPanel.CreateParams(var Params: TCreateParams);begin inherited CreateParams(Params); Params.ExStyle := Params.ExStyle + WS_EX_TRANSPARENT; ControlStyle := ControlStyle - [csOpaque] + [csAcceptsControls];end;procedure TTransPanel.Paint;const Alignments: array[TAlignment] of Longint = (DT_LEFT, DT_RIGHT, DT_CENTER);var Rect: TRect; FontHeight: Integer; Flags: Longint; sBlendFunction: BlendFunction;begin inherited Paint; with sBlendFunction do begin BlendOp := AC_SRC_OVER; BlendFlags := 0; AlphaFormat := 0; SourceConstantAlpha:= (255 * FBlendValue) div 100 ; end; Rect := GetClientRect; Buffer.Width:=Width; Buffer.Height:=Height; with Buffer.Canvas do begin Brush.Color:=FColor; FillRect(Rect); end; with Canvas do begin Windows.AlphaBlend(Canvas.Handle,0,0,Width, Height,Buffer.Canvas.Handle,0,0, Buffer.Width,Buffer.Height,sBlendFunction); if Fborder or (csDesigning in ComponentState) then begin Canvas.Brush.Color := clBtnShadow; Canvas.FrameRect(Rect); end; end;end;procedure TTransPanel.Setborder(Value: Boolean);begin if Value <> Fborder then begin Fborder := Value; RecreateWnd; end;end;procedure TTransPanel.WMWindowPosChanging(var Message: TWMWindowPosChanging);begin inherited; Invalidate;end;procedure TTransPanel.WMEraseBkgnd(var Message: TWmEraseBkgnd);begin Message.Result:= 1;end;procedure TTransPanel.SetAlignment(const Value: TAlignment);begin FAlignment := Value; RecreateWnd;end;procedure TTransPanel.SetColor(Value: TColor);begin if Value <> FColor then begin FColor := Value; RecreateWnd; end;end;procedure TTransPanel.SetBlendValue(const Value: TBlendValue);begin if FBlendValue <> Value then begin FBlendValue := Value; RecreateWnd; end;end;end.
测试过程中发现的问题:
1、设计时,两个TransPanel之前的BringtoFront、SendtoBack无效。
2、设计时,两个TransPanel部分重叠,失去焦点,背景里不完全重画。
3、设计时,同时选中两个TransPanel,透明效果会慢慢无效。
4、设计时,TransPanel在Button上层覆盖半个Button,然后移开Button。会发现Button前景没有重画。
总之问题还是很多。请达人帮忙完美一下
转自:http://bbs.2ccc.com/topic.asp?topicid=293675
- 半透明Panel控件问题
- panel控件
- Panel控件
- 多个panel控件重合使用时,某个panel控件不显示问题?
- winform 中panel动态添加控件坐标原点问题
- 解决java获取panel中所有控件的问题
- 控件透明与半透明
- MFC之半透明控件
- Panel创建动态控件
- Panel创建动态控件
- 面板控件(Panel)
- Panel控件的使用
- Panel控件应用
- winform自定义panel控件
- Panel和PlaceHolder控件
- android Panel控件 抽屉控件
- ASP:Panel控件(容器控件)
- Panel AutoScrollPosition 的问题
- Cocos2D-iphone CCLayer中的两种触摸(touch)处理方式
- Sftp和ftp 区别、工作原理等(汇总ing)
- hdu-统计元音
- CodeForces-MemSQL start[c]up Round 1-A. Square and Rectangles
- Starling在应用于移动设备开发时的注意事项
- 半透明Panel控件问题
- 专业学习中,学、用英语
- hdu-Palindromes _easy version
- 学生信息管理系统之模棱两可
- python join
- 项目中使用XML方式去取数据插入数据代码
- Linux 混杂设备的应用
- JavaScript学习笔记(三十七) 原型继承
- socket的shutdown和close