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;
は一種の面白いWindows 7の淫乱ハイブリッド雰囲気にXPのメニューを入れて検索します。 –
@David - あなたは私の溝を台無しにしてしまいます...私はこのメニューを考え続けていました...ちょっと涼しくて、彼は何をしていますか? – GDF
実際には、色を薄い青色にして、左に見栄えの良い勾配を付けるといいでしょう。とにかく個人的な選択のための個人的な選択です - それを見る必要はありません:) TToolBarと組み合わせてdsGradientに設定すると、大丈夫です。スクリーンショットは簡単な例でした。 –