delphi – 透明组框
发布时间:2020-12-15 04:13:13 所属栏目:大数据 来源:网络整理
导读:我继承了 TGroupBox的Delphi本机控件并覆盖其Paint方法以绘制圆角矩形. procedure TclTransparentGroupBox.CreateParams(var params : TCreateParams); begin inherited; Params.ExStyle := params.ExStyle or WS_EX_TRANSPARENT; end; 覆盖Create params后,
我继承了
TGroupBox的Delphi本机控件并覆盖其Paint方法以绘制圆角矩形.
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表示我们确实绘制了背景. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |