【问题标题】:TMainMenu is not shown when the vcl styles is removed from the NC Area从 NC 区域中删除 vcl 样式时,不显示 TMainMenu
【发布时间】:2012-08-15 02:41:09
【问题描述】:

我正在使用此代码从表单的非客户区中删除 vcl 样式。

type
  TFormStyleHookNC= class(TMouseTrackControlStyleHook)
  protected
    procedure PaintBackground(Canvas: TCanvas); override;
    constructor Create(AControl: TWinControl); override;
  end;

constructor TFormStyleHookNC.Create(AControl: TWinControl);
begin
  inherited;
  OverrideEraseBkgnd := True;
end;

procedure TFormStyleHookNC.PaintBackground(Canvas: TCanvas);
var
  Details: TThemedElementDetails;
  R: TRect;
begin
  if StyleServices.Available then
  begin
    Details.Element := teWindow;
    Details.Part := 0;
    R := Rect(0, 0, Control.ClientWidth, Control.ClientHeight);
    StyleServices.DrawElement(Canvas.Handle, Details, R);
  end;
end;


initialization
 TStyleManager.Engine.RegisterStyleHook(TForm3, TFormStyleHookNC);

在应用此样式钩子之前,表单看起来像

之后

您可以看到菜单消失了,问题是:我该如何解决这个问题?我的意思是如何在不删除 TMainMenu 的情况下从表单的非客户区删除 vcl 样式?

【问题讨论】:

    标签: delphi delphi-xe2 vcl-styles


    【解决方案1】:

    当您使用 vcl 样式时,TMain 菜单由 TMainMenuBarStyleHook vcl 样式钩子绘制,该钩子定义在 TFormStyleHook(表单的钩子)内部,在这种情况下,因为您没有使用它hook 没有绘制 TMainMenu 的代码。

    两种可能的解决方案是

    1) 在 TFormStyleHookNC 内部为 TMainMenu 实现 vcl 样式挂钩,就像 TFormStyleHook 一样。

    2) 甚至更好地使用 TActionMainMenuBar 组件而不是 TMainMenu,该组件与 vcl 样式很好地集成(查看下一个示例图像)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-03
      相关资源
      最近更新 更多