delphi - 当 vcl 样式从 NC 区域删除时,TMainMenu 不显示

标签 delphi delphi-xe2 vcl-styles

我使用此代码从表单的非客户区域中删除 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);

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

enter image description here

及之后

enter image description here

正如您所看到的,菜单消失了,问题是:我该如何解决这个问题?我的意思是如何从表单的非客户区域删除 vcl 样式而不删除 TMainMenu?

最佳答案

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

两种可能的解决方案是

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

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

enter image description here

关于delphi - 当 vcl 样式从 NC 区域删除时,TMainMenu 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11963441/

相关文章:

delphi - VCL风格mac外观风格设计师

delphi - 如何在启用 VCL 样式的情况下为 TComboBox 的背景着色

delphi - 类型上的构造函数不满足要求

delphi - delphi中如何将字符串剪切为所需的数字?

Delphi TSplitter 闪烁问题

Delphi - identcache 扩展

delphi - ZDecompressStream() 导致内存泄漏

performance - Delphi优化: constant loop

delphi - 是否可以购买/下载/试用 Adob​​e 产品中使用的组件,例如 (Adobe Encore) for delphi?

delphi - 使用 TIdTCPClient 异步读取