このコンポーネントから派生した独自のコンポーネントを作成して、TActionMainMenuBar を拡張しようとしています。
私がやろうとしていることの 1 つは、メニュー バーに沿ってグラデーションを描画できるようにすることです。私はこれを行うことができましたが、割り当てられた TActionManager が XPStyle に設定されている場合、メニュー項目に問題があります。
さまざまな TActionManager スタイルが設定されたこれらの画像を参照してください。
プラットフォームのデフォルト (マウスオーバーとプレス):
TActionManager が Platform Default に設定されている場合、背景が正しく表示され、グラデーションがきれいに表示されます。
ただし、TActionManager が XPStyle に設定されている場合、一部の項目でグラデーションが正しく描画されません。最初の項目を見てください。
XP スタイル (マウスオーバーとプレス):
ご覧のとおり見栄えがよくありません。
ペイントで画像を編集して、どのように見せたいかの大まかなアイデアを示しました。
マウスオーバーと選択
これにより、いくつかの興味深いメニュー スタイルを作成できると思います。
これが私がこれまでに持っているコードです:
unit uMyMenu;
interface
uses
Classes,
Types,
Graphics,
GraphUtil,
ActnMan,
ActnCtrls,
ActnMenus,
PlatformDefaultStyleActnCtrls,
XPActnCtrls,
XPStyleActnCtrls;
type
TMyActionMenu = class(TActionMainMenuBar)
private
FColorStart: TColor;
FColorEnd: TColor;
procedure SetColorStart(AValue: TColor);
procedure SetColorEnd(AValue: TColor);
protected
procedure Paint(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ColorStart: TColor read FColorStart write SetColorStart default clSkyBlue;
property ColorEnd: TColor read FColorEnd write SetColorEnd default clHighlight;
end;
procedure Register;
implementation
{ TMyActionMenu }
constructor TMyActionMenu.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
SetColorStart(clSkyBlue);
SetColorEnd(clHighlight);
ParentBackground := True;
ParentColor := False;
OnPaint := Paint;
end;
destructor TMyActionMenu.Destroy;
begin
inherited;
end;
procedure TMyActionMenu.SetColorStart(AValue: TColor);
begin
if FColorStart <> AValue then
begin
FColorStart := AValue;
Invalidate;
end;
end;
procedure TMyActionMenu.SetColorEnd(AValue: TColor);
begin
if FColorEnd <> AValue then
begin
FColorEnd := AValue;
Invalidate;
end;
end;
procedure TMyActionMenu.Paint(Sender: TObject);
var
Rect: TRect;
begin
Rect := GetClientRect;
GradientFillCanvas(TMyActionMenu(Sender).Canvas, FColorStart,
FColorEnd, Rect, gdVertical);
end;
procedure Register;
begin
RegisterComponents('Standard', [TMyActionMenu]);
end;
end.
どこから始めて何を変更すればよいかわかりませんので、コメントや回答をお待ちしています。
アップデート
たとえば、TActionMainMenuBar をグラデーション パネル内に配置し、ParentBackground を True に設定すると、より適切に機能します。したがって、SetSubComponent を使用して TMyActionMenu を同様のパネル コンテナーに配置し、その方法でパネルにグラデーションを描画することを検討する必要があります。
それまでの間、私はこの質問を開いたままにして、さらなるコメントや提案を求めます.