当从NC区域中删除vcl样式时,不会显示TMainMenu [英] TMainMenu is not shown when the vcl styles is removed from the NC Area

查看:433
本文介绍了当从NC区域中删除vcl样式时,不会显示TMainMenu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using this code to remove the vcl styles from the non client area of a form.

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);

在应用此样式钩子之前,窗体看起来像

Before to apply this style hook the form looks like

和之后

您可以看到菜单消失,问题是:我如何解决这个问题?我的意思是我可以从窗体的非客户区域中删除vcl样式,而不删除TMainMenu?

As you can see the menu disappears, The question is : how I can fix this? I mean how i can remove the vcl styles from the non client area of a form without remove the TMainMenu?

推荐答案

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

When you uses the vcl styles, the TMain menu is drawn by the TMainMenuBarStyleHook vcl style hook, which is defined inside of the TFormStyleHook (the hook of the forms), in this case because you are not using this hook there is not code to draw the TMainMenu.

两个可能的解决方案是

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

1) Implement the vcl style hook for the TMainMenu inside of the TFormStyleHookNC , just like the TFormStyleHook does.

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

2)or even better use a TActionMainMenuBar component instead of a TMainMenu, this component is very well integrated with the vcl styles (check the next sample image).

这篇关于当从NC区域中删除vcl样式时,不会显示TMainMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆