2012-02-24 10 views
2

TActionManagerにあるXPStyleを使用してメニューインターフェイスを作成するのが好きです。私は本当にサードパーティのコンポーネントを使用せずにしたいと思っTActionManagerの拡張 - ペイントグラデーション?

ことの一つは、メニューの側面に沿って勾配をレンダリングです:

enter image description here

XPColorMapがない限り、これを変更するために必要な性質を持っていないようです

私は本当に明白な何かを見過ごしています。

可能であれば、どうすればよいですか?

ありがとうございました。

UPDATE wp_1233996が提供する優れた情報とコードサンプルに

おかげで、ここでの結果である:

enter image description here

私は、これは厄介なXPスタイルのメニューでどのように表示されませんWindows 7でも?私はそれが本当に個人的に本当に良いと思う:)

+2

は一種の面白いWindows 7の淫乱ハイブリッド雰囲気にXPのメニューを入れて検索します。 –

+0

@David - あなたは私の溝を台無しにしてしまいます...私はこのメニューを考え続けていました...ちょっと涼しくて、彼は何をしていますか? – GDF

+0

実際には、色を薄い青色にして、左に見栄えの良い勾配を付けるといいでしょう。とにかく個人的な選択のための個人的な選択です - それを見る必要はありません:) TToolBarと組み合わせてdsGradientに設定すると、大丈夫です。スクリーンショットは簡単な例でした。 –

答えて

4

http://edn.embarcadero.com/article/33461アクションバーコンポーネントの背後にある魔法のいくつかを説明しているJeremy Northの素晴らしい記事へのリンク。私の解決策はこの記事に基づいています。

最初に、メニュー項目をペイントするクラスはTXPStyleMenuItem(Vcl.XPActnCtrls単位)です。 TXPStyleMenuItemから継承し、DrawBackgroundメソッドをオーバーライドする新しいクラスを作成します。新しいメソッドは、次のようになります。

uses 
    ..., Vcl.XPActnCtrls, Vcl.GraphUtil, ...; 

type 
    TMyStyleMenuItem = class(TXPStyleMenuItem) 
    protected 
    procedure DrawBackground(var PaintRect: TRect); override; 
end; 

procedure TMyStyleMenuItem.DrawBackground(var PaintRect: TRect); 
// Some lines are copied from Delphi's TXPStyleMenuItem.DrawBackground. 
var 
    BannerRect: TRect; 
    StartCol, EndCol: TColor; 
begin 
    inherited; 

    BannerRect := PaintRect; 
    BannerRect.Right := 25; 
    StartCol := clGray; //or: Actionbar.ColorMap.UnusedColor; 
    EndCol := clSilver; //or: Actionbar.ColorMap.Color; 
    GradientFillCanvas(Canvas, StartCol, EndCol, BannerRect, gdHorizontal); 

    if (Selected and Enabled) or (Selected and not MouseSelected) then 
    begin 
    if Enabled and not ActionBar.DesignMode then 
     if not Separator or (Separator and ActionBar.DesignMode) then 
     Canvas.Brush.Color := Menu.ColorMap.SelectedColor; 
    Dec(PaintRect.Right, 1); 
    end; 
    if (not ActionBar.DesignMode and Separator) then exit; 
    if not Mouse.IsDragging and ((Selected and Enabled) or 
    (Selected and not MouseSelected)) then 
    begin 
    Canvas.FillRect(PaintRect); 
    Canvas.Brush.Color := ActionBar.ColorMap.BtnFrameColor; 
    Inc(PaintRect.Right); 
    Canvas.FrameRect(PaintRect); 
    end; 
end; 

このコードでは、グラデーションの開始と終了の色はハードコードされています。柔軟性を高めるために、コメントに示されているようにカラーマップから色を取得するほうが良いかもしれません。

代わりに古いXPStyleMenuItemのこの新しいクラスを使用するためには、ActionMainMenubarのイベントOnGetControlClassのイベントハンドラを実装します。

procedure TForm1.ActionMainMenuBar1GetControlClass(Sender: TCustomActionBar; 
    AnItem: TActionClient; var ControlClass: TCustomActionControlClass); 
begin 
    if ControlClass.InheritsFrom(TXPStyleMenuItem) then 
    ControlClass := TMyStyleMenuItem; 
end;