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

时间:2012-08-15 02:41:09

标签: 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);

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

enter image description here

之后

enter image description here

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

1 个答案:

答案 0 :(得分:7)

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

两种可能的解决方案

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

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

enter image description here