Delphi XE2:在组件上禁用vcl Style

Delphi XE2:在组件上禁用vcl Style,第1张

概述我试图按照示例禁用表单上控件的颜色. TStyleManager.Engine.RegisterStyleHook(ClrMeans.TwwDBComboDLG,TEditStyleHook); 但是,当注册或取消注册第三方控件(infopower TwwDBComboDlg)或标准VCL TEdit时,我会收到异常.任何人对此或任何建议都有任何疑问 这里的 link解释了你需要知道的东西. 基本 我试图按照示例禁用表单上控件的颜色.

TStyleManager.Engine.RegisterStyleHook(ClrMeans.TwwDBComboDLG,TEditStyleHook);

但是,当注册或取消注册第三方控件(infopower TwwDBComboDlg)或标准VCL TEdit时,我会收到异常.任何人对此或任何建议都有任何疑问

解决方法 这里的 link解释了你需要知道的东西.

基本上,你需要在其中放入一个“空钩子”,这是你已经知道的,或者你需要放入一个“VCL颜色”钩子,这是你所缺少的一半.另一半是你的零指针问题.

为了使TEdit衍生物(和你的一样)看起来像VCL标准颜色,使它与你的控件一起工作所需的代码是这样的:

uses  WinAPI.Messages,Vcl.Controls,Vcl.StdCtrls,Vcl.Forms,Vcl.themes,Vcl.Styles;typeTEditStyleHookcolor = class(TEditStyleHook)  private    procedure Updatecolors;  protected    procedure WndProc(var Message: TMessage); overrIDe;    constructor Create(AControl: TWinControl); overrIDe;  end;implementationtype TWinControlH= class(TWinControl);constructor TEditStyleHookcolor.Create(AControl: TWinControl);begin  inherited;  //call the Updatecolors method to use the custom colors  Updatecolors;end;//Here you set the colors of the style hookprocedure TEditStyleHookcolor.Updatecolors;var  LStyle: TCustomStyleServices;begin if Control.Enabled then begin  Brush.color := TWinControlH(Control).color; //use the Control color  Fontcolor   := TWinControlH(Control).Font.color;//use the Control Font color end else begin  //if the control is Disabled use the colors of the style  LStyle := StyleServices;  Brush.color := LStyle.GetStylecolor(scEditDisabled);  Fontcolor := LStyle.GetStyleFontcolor(sfEditBoxTextDisabled); end;end;//Handle the messages of the controlprocedure TEditStyleHookcolor.WndProc(var Message: TMessage);begin  case Message.Msg of    CN_CTLcolorMSGBox..CN_CTLcolorSTATIC:      begin        //Get the colors        Updatecolors;        SetTextcolor(Message.WParam,colorToRGB(Fontcolor));        SetBkcolor(Message.WParam,colorToRGB(Brush.color));        Message.Result := LRESulT(Brush.Handle);        Handled := True;      end;    CM_ENABLEDCHANGED:      begin        //Get the colors        Updatecolors;        Handled := False;      end  else    inherited WndProc(Message);  end;end;Procedure ApplyVCLcolorsstyleHook(ControlClass :TClass);begin    if Assigned(TStyleManager.Engine) then       TStyleManager.Engine.RegisterStyleHook(ControlClass,TEditStyleHookcolor);end;initialization     ApplyVCLcolorsstyleHook(TwwDBComboDlg);

NIL的问题是,如果你没有打开VCL主题,那么Engine就是nil,你应该检查并从该代码返回而不调用你正在调用的那个函数.在这里您可以打开主题,以防错过它:

有趣的一面:获得the VCL Styles utils图书馆.这是一个使用它来改变东西颜色的例子:

TCustomStyleExt(TStyleManager.ActiveStyle).SetStylecolor(scEdit,clWindow); TCustomStyleExt(TStyleManager.ActiveStyle).SetStyleFontcolor(sfEditBoxTextnormal,clWindowText);

您可以创建样式,并将这些样式应用于特定控件,甚至可以扩展主题引擎,也可以使用VCL样式实用工具来获得所需的结果,但这不是一件容易的事.

总结

以上是内存溢出为你收集整理的Delphi XE2:在组件上禁用vcl Style全部内容,希望文章能够帮你解决Delphi XE2:在组件上禁用vcl Style所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1237438.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存