delphi – ActionBars中的XP Style Glyph烦恼
我不想问关于组件外观的太多问题,但是现在在应用程序中出现看起来同样重要.
无论如何,请看下面的图像: 两者都使用TActionManager和TActionMainMenuBar来创建我的主菜单.图像左侧的菜单使用平台默认样式,右侧的菜单使用我的TActionManager定义的XP样式. 请注意,当左侧菜单突出显示时,字形保持不变,这是完美的. 现在看看右边的XP风格菜单,字形绘制一个阴影,稍微弹出,你可以看到透明度使得字形看起来有些奇怪. 我想为我的UI启用XP风格,但我不喜欢绘制字形的方式.我还想将我的TToolbar更改为TActionToolBar并应用相同的XP样式,但这也会使字形也相同. 如何在TActionManager中定义XP样式菜单,而不是像这样渲染字形? 谢谢. 编辑 现在结果是,应用了以下答案中的一些技术: 克雷格. 解决方法
下面是一些覆盖XP STYLE的示例代码,创建一个可以根据需要调整的派生类.这里的第一步是替换你自己的派生菜单项类,并改变它的DrawGlyph代码,正如大卫告诉你的那样.我想你可以使用一些示例代码.
这只是一个快速演示.它不会在带有字形的已检查项目周围绘制框,因此此自定义样式与已检查项目不兼容,除非它们没有字形.您必须弄清楚如何绘制checked-glyph项目(如果设置了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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |