4

I dont like to ask too many questions in relation to the appearance of components, but these days appearance in Applications seems just as important.

Anyway, please see the below images:

enter image description here

Both are using the TActionManager and TActionMainMenuBar to create my main menu. The menu in the left of the image is using the Platform Default Style, the menu on the right is using the XP style defined by my TActionManager.

Notice how when the left menu is highlighted, the glyph remains the same which is perfect.

Now look at the XP style menu on the right, the glyph draws a drop shadow, pops out slightly and you can see the transparency makes the glyph appear slightly odd.

I want to enable the XP style for my UI, but the way the glyphs are painted I do not like. I also want to change my TToolbar to a TActionToolBar and apply the same XP style, but this will render the glyphs the same too.

How can I make the XP style menu defined in the TActionManager, not render the glyphs like this?

Thanks.

EDIT

This is now the result, having applied some of the techniques from the answers below:

enter image description here

Craig.

4

2 に答える 2

6

XP STYLEをオーバーライドして、必要に応じて微調整できる派生クラスを作成するサンプルコードを次に示します。ここでの最初のステップは、Davidが言ったように、独自の派生メニュー項目クラスを置き換え、そのDrawGlyphコードを変更することです。サンプルコードを使用できると思いました。

これは簡単なデモです。グリフのあるチェックされたアイテムの周りにボックスを描画しないため、このカスタムスタイルは、グリフがない場合を除いて、チェックされたアイテムと互換性がありません。チェックされたグリフアイテムをどのように描画するかを理解する必要があります(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.
于 2011-05-15T02:50:52.543 に答える
1

これは、VCLコードの設計によって行われます。関連するコードはTXPStyleMenuItem.DrawGlyph()XPActnCtrls.pasにあります。

動作を変更する最も簡単な方法は、に基づいて独自のバージョンのXPアクションバースタイルを登録することTXPStyleActionBarsです。をオーバーライドできるフックはたくさんありますTXPStyleMenuItem.DrawGlyph()

于 2011-05-14T21:52:12.693 に答える