如何用Delphi制作360安全卫士的部分风格!! 如何用Delphi制作360安全卫士的部分风格,如下图:(主要透明效果) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 TMS控件能够做到这个样式,不过皮肤还是要自己来做的。 透明效果这个,你只要在控件绘制之前先绘制父控件的图片就行了。最简单的方法是通过消息,让父控件绘制: Self.Parent.Perform(WM_ERASEBKGND, DC, 0); Self.Parent.Perform(WM_PrintClient, DC, prf_Client);透明图片的话,如果要求不高,比如不需要拉伸,透明度调节,灰度等等呢,那么PngImage就可以了,毕竟GDI速度快是王道我建议楼主学习一下功能强大的GDI+,呵呵,省去很多烦恼。。 TMS哪个控件有这个 能详细说下吗?能不能提供下TMS控件 我邮箱 [email protected] 完全用画的就行了吧在"不得闲" 的控件里面看过透明的 button 有很多用Delphi写的卫士,360的不少边缘作品一开始也是Delphi写的 你留个邮箱吧,有空我发个DEMO控件的代码给你参考参考,按你贴的图,基本上是要实现一个透明按钮,原理么,楼上也有人说了,用自绘, 也发一个给我把,[email protected] 谢谢 BodSoft DirectUI Library V1.3网上搜一下,目前流行软件的界面都可以模仿。 DEMO已发邮箱,效果基本上是这样:正常状态,鼠标停靠状态,鼠标按下状态为了附带一些BUTTON的属性,特地尝试了一下从TBUTTON继承而不是我经常用的TCustomControl,不过基本上也差不多在这里贴一份控件的代码,很多公共函数没附上,但控件自绘的普通方法就是这样,没有什么难度和神秘的unit Skin360Button;interfaceuses Windows,SysUtils,Classes,Controls,StdCtrls,Messages,Graphics, GdiPlus,GdiSkinHelper,GdiPlusHelpers,Math;type TSkin360Button=class(TCustomButton) private FMouseDown:Boolean; FCanvas:TCanvas; FParentBkGndBitmap:TBitmap; FHoverPicture: TPicture; FDownPicture: TPicture; FHoverBitmap: IGPBitmap; FDownBitmap: IGPBitmap; FIconBitmap:IGPBitmap; FIconPicture: TPicture; FIconHeight: Integer; FIconWidth: Integer; procedure OnIconPictureChanged(Sender:TObject); procedure OnHoverPictureChanged(Sender:TObject); procedure OnDownPictureChanged(Sender:TObject); procedure SetDownPicture(const Value: TPicture); procedure SetHoverPicture(const Value: TPicture); procedure MakeGPBitmapByPicture(var ABitmap: IGPBitmap; APicture: TPicture); procedure SetIconPicture(const Value: TPicture); procedure SetIconHeight(const Value: Integer); procedure SetIconWidth(const Value: Integer); protected procedure Paint;virtual; procedure PaintWindow(DC:HDC); procedure WMPaint(var Message:TWMPaint);message WM_PAINT; procedure WMEraseBkGnd(var Message:TWMEraseBkGnd);message WM_ERASEBKGND; procedure WMLButtonDown(var Message:TMessage);message WM_LBUTTONDOWN; procedure WMLButtonUp(var Message:TMessage);message WM_LBUTTONUP; public constructor Create(AOwner:TComponent);override; destructor Destroy;override; published property HoverPicture:TPicture read FHoverPicture write SetHoverPicture; property DownPicture:TPicture read FDownPicture write SetDownPicture; property IconPicture:TPicture read FIconPicture write SetIconPicture; property IconWidth:Integer read FIconWidth write SetIconWidth; property IconHeight:Integer read FIconHeight write SetIconHeight; published property Action; property Align; property Anchors; property BiDiMode; property Cancel; property Caption; property CommandLinkHint; property Constraints; property Default; property DisabledImageIndex; property DoubleBuffered; property DragCursor; property DragKind; property DragMode; property DropDownMenu; property ElevationRequired; property Enabled; property Font; property HotImageIndex; property ImageAlignment; property ImageIndex; property ImageMargins; property Images; property ModalResult; property ParentBiDiMode; property ParentDoubleBuffered; property ParentFont; property ParentShowHint; property PopupMenu; property PressedImageIndex; property SelectedImageIndex; property ShowHint; property Style; property TabOrder; property TabStop; property Visible; property WordWrap; property OnClick; property OnContextPopup; property OnDragDrop; property OnDragOver; property OnDropDownClick; property OnEndDock; property OnEndDrag; property OnEnter; property OnExit; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseActivate; property OnMouseDown; property OnMouseEnter; property OnMouseLeave; property OnMouseMove; property OnMouseUp; property OnStartDock; property OnStartDrag; end;procedure Register;implementationprocedure Register;begin RegisterComponents('SkinEngine',[TSkin360Button]);end;{ TSkin360Button }procedure DrawParentImageDefault(ASelf: TControl; DC: HDC);var SaveIndex: Integer; P: TPoint;begin if ASelf.Parent=nil then Exit; if Not (csDesigning in ASelf.ComponentState) then begin SaveIndex := SaveDC(DC); GetViewportOrgEx(DC, P); SetViewportOrgEx(DC, P.X - ASelf.Left, P.Y - ASelf.Top, nil); IntersectClipRect(DC, 0, 0, ASelf.Parent.Width, ASelf.Parent.Height); ASelf.Parent.Perform(WM_ERASEBKGND, DC, 0); ASelf.Parent.Perform(WM_PrintClient, DC, prf_Client); RestoreDC(DC, SaveIndex); end;end;procedure TSkin360Button.MakeGPBitmapByPicture(var ABitmap:IGPBitmap;APicture:TPicture);begin if (APicture.Graphic=nil) or APicture.Graphic.Empty then begin ABitmap:=nil; end else begin ABitmap:=TSkinHelper.CreateBitmap(APicture.Graphic) end;end;constructor TSkin360Button.Create(AOwner: TComponent);begin inherited; FHoverPicture:=TPicture.Create; FDownPicture:=TPicture.Create; FIconPicture:=TPicture.Create; FHoverPicture.OnChange:=Self.OnHoverPictureChanged; FDownPicture.OnChange:=Self.OnDownPictureChanged; FIconPicture.OnChange:=Self.OnIconPictureChanged; FParentBkGndBitmap:=TBitmap.Create; FCanvas := TControlCanvas.Create; TControlCanvas(FCanvas).Control := Self; FIconHeight:=16; FIconWidth:=16;end;destructor TSkin360Button.Destroy;begin FIconPicture.Free; FHoverPicture.Free; FDownPicture.Free; FParentBkGndBitmap.Free; FCanvas.Free; inherited;end;procedure TSkin360Button.OnDownPictureChanged(Sender: TObject);begin MakeGPBitmapByPicture(FDownBitmap,FDownPicture);end;procedure TSkin360Button.OnHoverPictureChanged(Sender: TObject);begin MakeGPBitmapByPicture(FHoverBitmap,FHoverPicture);end;procedure TSkin360Button.OnIconPictureChanged(Sender: TObject);begin MakeGPBitmapByPicture(FIconBitmap,FIconPicture);end;procedure TSkin360Button.Paint;var tmpBitmap:IGPBitmap; tmpIconDrawRect:TRect; tmpCaptionDrawRect:TRect; tmpGraphics:IGPGraphics;begin FParentBkGndBitmap.SetSize(Width,Height); //绘制父控件到缓存位图 DrawParentImageDefault(Self,FParentBkGndBitmap.Canvas.Handle); tmpBitmap:=nil; if Self.FMouseDown then begin tmpBitmap:=Self.FDownBitmap; end else if Self.MouseInClient then begin tmpBitmap:=Self.FHoverBitmap; end; //绘制背景图片 if (tmpBitmap<>nil) then begin //九宫格绘制 TSkinHelper.StretchDrawImageInRectByMargins(FParentBkGndBitmap.Canvas.ToGPGraphics, tmpBitmap, TGPRect.Create(0,0,Width,Height), 8,8,8,8); end; //确定图标的绘制矩形 tmpIconDrawRect.Left:=Ceil((Width-Self.FIconWidth) / 2); tmpIconDrawRect.Top:=5; tmpIconDrawRect.Right:=tmpIconDrawRect.Left+Self.FIconWidth; tmpIconDrawRect.Bottom:=tmpIconDrawRect.Top+Self.FIconHeight; //绘制标题的绘制矩形 tmpCaptionDrawRect.Left:=Ceil((Width-TSkinHelper.CalcFontWidth(FParentBkGndBitmap.Canvas.ToGPGraphics,Caption,Font)) / 2); tmpCaptionDrawRect.Top:=tmpIconDrawRect.Bottom+5; tmpCaptionDrawRect.Right:=Width; tmpCaptionDrawRect.Bottom:=Height; //绘制标题 tmpGraphics:=FParentBkGndBitmap.Canvas.ToGPGraphics; tmpGraphics.TextRenderingHint:=TGPTextRenderingHint.TextRenderingHintAntiAlias; TSkinHelper.DrawShadowText(tmpGraphics, Caption,Font, tmpCaptionDrawRect.Left, tmpCaptionDrawRect.Top, 3,0, TGPColor.CreateFromColorRef(clWhite)); //绘制图标 TSkinHelper.StretchDrawImageInRect(FParentBkGndBitmap.Canvas.ToGPGraphics, Self.FIconBitmap, TGPRect.Create(tmpIconDrawRect)); //显示到界面上 Bitblt(FCanvas.Handle,0,0,Width,Height, FParentBkGndBitmap.Canvas.Handle,0,0,SRCCOPY);end;procedure TSkin360Button.PaintWindow(DC: HDC);begin FCanvas.Lock; try FCanvas.Handle := DC; try TControlCanvas(FCanvas).UpdateTextFlags; Paint; finally FCanvas.Handle := 0; end; finally FCanvas.Unlock; end;end;procedure TSkin360Button.SetDownPicture(const Value: TPicture);begin FDownPicture.Assign(Value); Invalidate;end;procedure TSkin360Button.SetHoverPicture(const Value: TPicture);begin FHoverPicture.Assign(Value); Invalidate;end;procedure TSkin360Button.SetIconHeight(const Value: Integer);begin if FIconHeight<>Value then begin FIconHeight := Value; Invalidate; end;end;procedure TSkin360Button.SetIconPicture(const Value: TPicture);begin FIconPicture.Assign(Value); Invalidate;end;procedure TSkin360Button.SetIconWidth(const Value: Integer);begin if FIconWidth<>Value then begin FIconWidth := Value; Invalidate; end;end;procedure TSkin360Button.WMEraseBkGnd(var Message: TWMEraseBkGnd);begin Message.Result:=1;end;procedure TSkin360Button.WMLButtonDown(var Message: TMessage);begin Inherited; Self.FMouseDown:=True; Invalidate;end;procedure TSkin360Button.WMLButtonUp(var Message: TMessage);begin Inherited; Self.FMouseDown:=False; Invalidate;end;procedure TSkin360Button.WMPaint(var Message: TWMPaint);var DC: HDC; PS: TPaintStruct;begin DC := Message.DC; if DC = 0 then DC := BeginPaint(Handle, PS); try PaintWindow(DC); finally if Message.DC = 0 then EndPaint(Handle, PS); end;end;end. DelphiTeacher您好 能发份给我吗? 已经收到,好像Delphi 7里安装不了该组件 你的组件是D2007的吗? 发一份给我谢谢[email protected] 有没有办法将STRINGGRID的最后两行变成一列? GetWindowLong参数问题 发布作品和散分:《泡泡堂单机版》 问一个小问题?在线等待! 关于存储过程的问题,困扰多天请高手拔'键'相助!!! 日期型字段问题求教!! 一个具有挑战性的问题:如何实现delphi窗体的记忆功能?! 先进先出,先进后出,加权平均移动算法 好象每次转移贴子就要减掉一分信 誉 值??????:( 如何向一个函数的参数传递动态数组指针 Delphi6 Fastreport问题 如果制作透明大按钮
最简单的方法是通过消息,让父控件绘制:
Self.Parent.Perform(WM_ERASEBKGND, DC, 0);
Self.Parent.Perform(WM_PrintClient, DC, prf_Client);
透明图片的话,如果要求不高,比如不需要拉伸,透明度调节,灰度等等呢,那么PngImage就可以了,毕竟GDI速度快是王道
我建议楼主学习一下功能强大的GDI+,呵呵,省去很多烦恼。。
按你贴的图,基本上是要实现一个透明按钮,原理么,楼上也有人说了,用自绘,
效果基本上是这样:正常状态,鼠标停靠状态,鼠标按下状态为了附带一些BUTTON的属性,特地尝试了一下从TBUTTON继承而不是我经常用的TCustomControl,
不过基本上也差不多
在这里贴一份控件的代码,很多公共函数没附上,但控件自绘的普通方法就是这样,没有什么难度和神秘的unit Skin360Button;interfaceuses
Windows,SysUtils,Classes,Controls,StdCtrls,Messages,Graphics,
GdiPlus,GdiSkinHelper,GdiPlusHelpers,Math;type
TSkin360Button=class(TCustomButton)
private
FMouseDown:Boolean;
FCanvas:TCanvas;
FParentBkGndBitmap:TBitmap;
FHoverPicture: TPicture;
FDownPicture: TPicture;
FHoverBitmap: IGPBitmap;
FDownBitmap: IGPBitmap;
FIconBitmap:IGPBitmap;
FIconPicture: TPicture;
FIconHeight: Integer;
FIconWidth: Integer;
procedure OnIconPictureChanged(Sender:TObject);
procedure OnHoverPictureChanged(Sender:TObject);
procedure OnDownPictureChanged(Sender:TObject);
procedure SetDownPicture(const Value: TPicture);
procedure SetHoverPicture(const Value: TPicture);
procedure MakeGPBitmapByPicture(var ABitmap: IGPBitmap; APicture: TPicture);
procedure SetIconPicture(const Value: TPicture);
procedure SetIconHeight(const Value: Integer);
procedure SetIconWidth(const Value: Integer);
protected
procedure Paint;virtual;
procedure PaintWindow(DC:HDC);
procedure WMPaint(var Message:TWMPaint);message WM_PAINT;
procedure WMEraseBkGnd(var Message:TWMEraseBkGnd);message WM_ERASEBKGND;
procedure WMLButtonDown(var Message:TMessage);message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Message:TMessage);message WM_LBUTTONUP;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
property HoverPicture:TPicture read FHoverPicture write SetHoverPicture;
property DownPicture:TPicture read FDownPicture write SetDownPicture;
property IconPicture:TPicture read FIconPicture write SetIconPicture;
property IconWidth:Integer read FIconWidth write SetIconWidth;
property IconHeight:Integer read FIconHeight write SetIconHeight;
published
property Action;
property Align;
property Anchors;
property BiDiMode;
property Cancel;
property Caption;
property CommandLinkHint;
property Constraints;
property Default;
property DisabledImageIndex;
property DoubleBuffered;
property DragCursor;
property DragKind;
property DragMode;
property DropDownMenu;
property ElevationRequired;
property Enabled;
property Font;
property HotImageIndex;
property ImageAlignment;
property ImageIndex;
property ImageMargins;
property Images;
property ModalResult;
property ParentBiDiMode;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property PressedImageIndex;
property SelectedImageIndex;
property ShowHint;
property Style;
property TabOrder;
property TabStop;
property Visible;
property WordWrap;
property OnClick;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnDropDownClick;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
procedure Register;implementationprocedure Register;
begin
RegisterComponents('SkinEngine',[TSkin360Button]);
end;{ TSkin360Button }
procedure DrawParentImageDefault(ASelf: TControl; DC: HDC);
var
SaveIndex: Integer;
P: TPoint;
begin
if ASelf.Parent=nil then Exit;
if Not (csDesigning in ASelf.ComponentState) then
begin
SaveIndex := SaveDC(DC);
GetViewportOrgEx(DC, P);
SetViewportOrgEx(DC, P.X - ASelf.Left, P.Y - ASelf.Top, nil);
IntersectClipRect(DC, 0, 0, ASelf.Parent.Width, ASelf.Parent.Height);
ASelf.Parent.Perform(WM_ERASEBKGND, DC, 0);
ASelf.Parent.Perform(WM_PrintClient, DC, prf_Client);
RestoreDC(DC, SaveIndex);
end;
end;procedure TSkin360Button.MakeGPBitmapByPicture(var ABitmap:IGPBitmap;APicture:TPicture);
begin
if (APicture.Graphic=nil)
or APicture.Graphic.Empty then
begin
ABitmap:=nil;
end
else
begin
ABitmap:=TSkinHelper.CreateBitmap(APicture.Graphic)
end;
end;constructor TSkin360Button.Create(AOwner: TComponent);
begin
inherited;
FHoverPicture:=TPicture.Create;
FDownPicture:=TPicture.Create;
FIconPicture:=TPicture.Create;
FHoverPicture.OnChange:=Self.OnHoverPictureChanged;
FDownPicture.OnChange:=Self.OnDownPictureChanged;
FIconPicture.OnChange:=Self.OnIconPictureChanged; FParentBkGndBitmap:=TBitmap.Create;
FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self; FIconHeight:=16;
FIconWidth:=16;
end;destructor TSkin360Button.Destroy;
begin
FIconPicture.Free;
FHoverPicture.Free;
FDownPicture.Free;
FParentBkGndBitmap.Free;
FCanvas.Free;
inherited;
end;procedure TSkin360Button.OnDownPictureChanged(Sender: TObject);
begin
MakeGPBitmapByPicture(FDownBitmap,FDownPicture);
end;
procedure TSkin360Button.OnHoverPictureChanged(Sender: TObject);
begin
MakeGPBitmapByPicture(FHoverBitmap,FHoverPicture);
end;procedure TSkin360Button.OnIconPictureChanged(Sender: TObject);
begin
MakeGPBitmapByPicture(FIconBitmap,FIconPicture);
end;procedure TSkin360Button.Paint;
var
tmpBitmap:IGPBitmap;
tmpIconDrawRect:TRect;
tmpCaptionDrawRect:TRect;
tmpGraphics:IGPGraphics;
begin
FParentBkGndBitmap.SetSize(Width,Height);
//绘制父控件到缓存位图
DrawParentImageDefault(Self,FParentBkGndBitmap.Canvas.Handle); tmpBitmap:=nil;
if Self.FMouseDown then
begin
tmpBitmap:=Self.FDownBitmap;
end
else if Self.MouseInClient then
begin
tmpBitmap:=Self.FHoverBitmap;
end;
//绘制背景图片
if (tmpBitmap<>nil) then
begin
//九宫格绘制
TSkinHelper.StretchDrawImageInRectByMargins(FParentBkGndBitmap.Canvas.ToGPGraphics,
tmpBitmap,
TGPRect.Create(0,0,Width,Height),
8,8,8,8);
end;
//确定图标的绘制矩形
tmpIconDrawRect.Left:=Ceil((Width-Self.FIconWidth) / 2);
tmpIconDrawRect.Top:=5;
tmpIconDrawRect.Right:=tmpIconDrawRect.Left+Self.FIconWidth;
tmpIconDrawRect.Bottom:=tmpIconDrawRect.Top+Self.FIconHeight;
//绘制标题的绘制矩形
tmpCaptionDrawRect.Left:=Ceil((Width-TSkinHelper.CalcFontWidth(FParentBkGndBitmap.Canvas.ToGPGraphics,Caption,Font)) / 2);
tmpCaptionDrawRect.Top:=tmpIconDrawRect.Bottom+5;
tmpCaptionDrawRect.Right:=Width;
tmpCaptionDrawRect.Bottom:=Height;
//绘制标题
tmpGraphics:=FParentBkGndBitmap.Canvas.ToGPGraphics;
tmpGraphics.TextRenderingHint:=TGPTextRenderingHint.TextRenderingHintAntiAlias;
TSkinHelper.DrawShadowText(tmpGraphics,
Caption,Font,
tmpCaptionDrawRect.Left,
tmpCaptionDrawRect.Top,
3,0,
TGPColor.CreateFromColorRef(clWhite));
//绘制图标
TSkinHelper.StretchDrawImageInRect(FParentBkGndBitmap.Canvas.ToGPGraphics,
Self.FIconBitmap,
TGPRect.Create(tmpIconDrawRect));
//显示到界面上
Bitblt(FCanvas.Handle,0,0,Width,Height,
FParentBkGndBitmap.Canvas.Handle,0,0,SRCCOPY);
end;procedure TSkin360Button.PaintWindow(DC: HDC);
begin
FCanvas.Lock;
try
FCanvas.Handle := DC;
try
TControlCanvas(FCanvas).UpdateTextFlags;
Paint;
finally
FCanvas.Handle := 0;
end;
finally
FCanvas.Unlock;
end;
end;procedure TSkin360Button.SetDownPicture(const Value: TPicture);
begin
FDownPicture.Assign(Value);
Invalidate;
end;
procedure TSkin360Button.SetHoverPicture(const Value: TPicture);
begin
FHoverPicture.Assign(Value);
Invalidate;
end;procedure TSkin360Button.SetIconHeight(const Value: Integer);
begin
if FIconHeight<>Value then
begin
FIconHeight := Value;
Invalidate;
end;
end;procedure TSkin360Button.SetIconPicture(const Value: TPicture);
begin
FIconPicture.Assign(Value);
Invalidate;
end;procedure TSkin360Button.SetIconWidth(const Value: Integer);
begin
if FIconWidth<>Value then
begin
FIconWidth := Value;
Invalidate;
end;
end;
procedure TSkin360Button.WMEraseBkGnd(var Message: TWMEraseBkGnd);
begin
Message.Result:=1;
end;procedure TSkin360Button.WMLButtonDown(var Message: TMessage);
begin
Inherited;
Self.FMouseDown:=True;
Invalidate;
end;procedure TSkin360Button.WMLButtonUp(var Message: TMessage);
begin
Inherited;
Self.FMouseDown:=False;
Invalidate;
end;procedure TSkin360Button.WMPaint(var Message: TWMPaint);
var
DC: HDC;
PS: TPaintStruct;
begin
DC := Message.DC;
if DC = 0 then DC := BeginPaint(Handle, PS);
try
PaintWindow(DC);
finally
if Message.DC = 0 then EndPaint(Handle, PS);
end;
end;
end.
DelphiTeacher
您好 能发份给我吗?
[email protected]