delphi - ActionBar 中的 XP 样式字形烦恼

标签 delphi glyph

我不想问太多有关组件外观的问题,但如今应用程序中的外观似乎同样重要。

无论如何,请看下面的图片:

enter image description here

两者都使用 TActionManager 和 TActionMainMenuBar 来创建我的主菜单。图像左侧的菜单使用平台默认样式,右侧的菜单使用我的 TActionManager 定义的 XP 样式。

请注意,当左侧菜单突出显示时,字形保持不变,这是完美的。

现在看右侧的XP样式菜单,字形绘制了阴影,稍微弹出,您可以看到透明度使字形显得有点奇怪。

我想为我的 UI 启用 XP 风格,但我不喜欢绘制字形的方式。我还想将 TToolbar 更改为 TActionToolBar 并应用相同的 XP 样式,但这也会呈现相同的字形。

如何制作在 TAc​​tionManager 中定义的 XP 样式菜单,而不是像这样渲染字形?

谢谢。

编辑

这就是应用了以下答案中的一些技术后的结果:

enter image description here

克雷格。

最佳答案

这里是一些覆盖 XP STYLE 的示例代码,创建了一个您可以根据需要进行调整的派生类。这里的第一步是替换您自己的派生菜单项类,并更改其 DrawGlyph 代码,正如 David 告诉您的那样。我想你也许可以使用一些示例代码。

这只是一个快速演示。它不会在带有字形的选中项周围绘制一个框,因此此自定义样式与选中项不兼容,除非它们没有字形。您必须弄清楚要如何绘制选中的字形项(如果设置了 Action.Checked 属性,那么我编写 DrawGlyphFrame 的地方将是添加一些内容以在字形周围绘制选中状态矩形的好地方)。

unit MyActionControlStyle;

// Using this unit: Add it to your project. In your project set your
// style at runtime, add the unit to your uses clause and then set the style
// in that form's formcreate event:
//   ActionManager1.Style := MyActionControlStyle.MyStyle;

interface

uses Forms,
     Types,
     Controls,
     XPActnCtrls,
     XPStyleActnCtrls,
     ActnMan,
     ActnList,
     ActnMenus,
     ActnCtrls;

type

 TMyStyleMenuItem = class(TXPStyleMenuItem)
  protected
      procedure DrawGlyph(const Location: TPoint); override;

//      procedure DrawGlyphFrame(const Location:TPoint);

 end;
 TMyStyleMenuButton = class(TXPStyleMenuButton)
 end;

 TMyStyleActionBars = class(TXPStyleActionBars)
   // override the stuff that I want different than XP Style:
    function GetControlClass(ActionBar: TCustomActionBar;
      AnItem: TActionClientItem): TCustomActionControlClass; override;

 end;

var
 MyStyle:TMyStyleActionBars;

implementation


uses ToolWin, Classes, Windows, Graphics, GraphUtil, ImgList;
{ TMyStyleActionBars }

function TMyStyleActionBars.GetControlClass(ActionBar: TCustomActionBar;
  AnItem: TActionClientItem): TCustomActionControlClass;
begin
 if ActionBar is TCustomActionPopupMenu then
    Result := TMyStyleMenuItem
  else
  if ActionBar is TCustomActionMainMenuBar then
    Result := TMyStyleMenuButton
  else
    Result := inherited GetControlClass(ActionBar,AnItem);

end;

{ TMyStyleMenuItem }

procedure TMyStyleMenuItem.DrawGlyph(const Location: TPoint);
var
  ImageList: TCustomImageList;
  DrawEnabled: Boolean;
begin
//  DrawGlyphFrame(Location);
  if not HasGlyph and IsChecked then
  begin
    Canvas.Pen.Color := ActionBar.ColorMap.FontColor;
    DrawCheck(Canvas, Point((TextBounds.Left - 5) div 2, Height div 2), 2);
  end;

  if not HasGlyph then exit;
  if Assigned(Action) then
    ImageList := ActionClient.Action.ActionList.Images
  else
    ImageList := ActionClient.OwningCollection.ActionManager.Images;
  if not Assigned(ImageList) then exit;
  DrawEnabled := Enabled and (ActionClient.ImageIndex <> -1) or
    (csDesigning in ComponentState);
  ImageList.Draw(Canvas, Location.X, Location.Y, ActionClient.ImageIndex,
    dsTransparent, itImage, DrawEnabled);

end;

initialization
  MyStyle := TMyStyleActionBars.Create;
  RegisterActnBarStyle(MyStyle);
finalization
  UnregisterActnBarStyle(MyStyle);
  MyStyle.Free;
end.

关于delphi - ActionBar 中的 XP 样式字形烦恼,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6004439/

相关文章:

delphi - Delphi中无法在Exit语句处设置断点?

delphi - 使用 Delphi Tokyo 10.2 通过 GetObjectProp 获取 TextSettings.Font.Style 属性

delphi - `TWaitResult.wrIOCompletion` 未记录。谁能提供使用技巧?

java - 调整 iText 中的 TextMatrix

css - Sencha Architect ExtJs 应用程序中的 Icomoon 字形无法正常工作

html - 如何对验证的输入[类型 ="submit"] 的值进行编码

delphi - 如何将 Advantage API 示例 C 代码转换为 Delphi

delphi - 我可以将 Base 接口(interface)类型强制转换为 Derived 接口(interface)类型吗?

unicode - 组合任意 Unicode 符号或具有负宽度的 Unicode 字符

c++ - 如何使用 freetype 库使字形变粗?