大佬教程收集整理的这篇文章主要介绍了delphi – 透明组框,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
procedure TclTransparentGroupBox.CreateParams(var params : TCreateParams); begin inherited; Params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT; end;
覆盖Create params后,Paint方法如下所示.
procedure TclTransparentGroupBox.Paint; begin // Draw the rounded rect to show the group box bounds Canvas.Pen.Color := clWindowFrame; Canvas.RoundRect(5,15,ClientRect.Right - 5,ClientRect.bottom - 5,10,10); if Caption <> EmptyStr then begin Canvas.brush.Style := bsClear; Canvas.TextOut(10,Caption); end; end;
我面临的主要问题是,透明组框顶部的标签很少.当我打开表单时,标签看起来很好,但是当文本更改时,标签的某些边界矩形将是可见的.这在透明盒子上看起来很奇怪.
即使我调整表单大小,组合框本身也会消失,当我将焦点更改为另一个应用程序并带回我的应用程序时,组合框会自行绘制.
我错过了关于绘画的任何内容吗?我需要照顾的任何Windows消息???
提前致谢
拉胡尔
使它不透明
ControlStyle := ControlStyle - [csOpaque]
处理WM_ERASEBKGND:
procedure TTransPanel.WM_ERASEBKGND(var Msg: TWM_ERASEBKGND); var SaveDCInd: Integer; Position: TPoint; begin SaveDCInd := SaveDC(Msg.DC); //save device context state (TCanvas does not have that funC) GetViewportOrgEx(Msg.DC,Position); SetViewportOrgEx(Msg.DC,Position.X - Left,Position.Y - Top,nil); IntersectClipRect(Msg.DC,Parent.ClientWidth,Parent.ClientHeight); try Parent.Perform(WM_ERASEBKGND,Msg.DC,0 ); Parent.Perform(WM_PAINT,0); //or // Parent.Perform(WM_PRINTCLIENT,prf_Client); //Themeing except end; RestoreDC(Msg.DC,SaveDCInd); Canvas.refresh; Msg.Result := 1; //We painted out BACkground end;
在上面的过程中,您首先保存设备上下文状态,然后将我们的父(可能是TForm)的画布绘制到我们的画布上(TGroupBoX).最后恢复DC并返回1表示我们确实绘制了背景.
以上是大佬教程为你收集整理的delphi – 透明组框全部内容,希望文章能够帮你解决delphi – 透明组框所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。