TActionMainMenuBar主菜单项切换在Delphi 7中断断续续

时间:2016-06-24 09:38:56

标签: delphi menu delphi-7

我在Delphi 7项目中使用TActionToolBar和TActionMainMenuBar。当我浏览一个主菜单并且我想要彼此更改(4ex文件进行编辑)时,我必须在另一个菜单项上单击两次以进行更改(1.,关闭第一个,2。,打开新的子菜单)。使用TMainMenu这是无缝的,只需移动另一个菜单项,子菜单就会自动更改。我应该覆盖哪些消息,或者我应该用什么api调用来实现类似TMainMenu的行为?必须有一个解决方案,因为Delphi 7 IDE使用相同的组件,其行为是正确的。

dclact70.bpl的日期:10.08.2002(dd.mm.yyyy)

Unit1.pas:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ActnList, XPStyleActnCtrls, ActnMan, ToolWin, ActnCtrls,
  ActnMenus;

type
  TForm1 = class(TForm)
    ActionMainMenuBar1: TActionMainMenuBar;
    ActionManager1: TActionManager;
    Action1: TAction;
    Action1_1: TAction;
    Action1_2: TAction;
    Action2: TAction;
    Action2_1: TAction;
    Action2_2: TAction;
    procedure emptyActionHandler(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.emptyActionHandler(Sender: TObject);
begin
//
end;

end.

unit1.dfm:

object Form1: TForm1
  Left = 584
  Top = 180
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ActionMainMenuBar1: TActionMainMenuBar
    Left = 0
    Top = 0
    Width = 854
    Height = 29
    ActionManager = ActionManager1
    Caption = 'ActionMainMenuBar1'
    ColorMap.HighlightColor = clWhite
    ColorMap.BtnSelectedColor = clBtnFace
    ColorMap.UnusedColor = clWhite
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clMenuText
    Font.Height = -12
    Font.Name = 'Segoe UI'
    Font.Style = []
    Spacing = 0
  end
  object ActionManager1: TActionManager
    ActionBars = <
      item
        Items = <
          item
            Items = <
              item
                Action = Action1_1
                Caption = '&Action1_1'
              end
              item
                Action = Action1_2
                Caption = 'A&ction1_2'
              end>
            Action = Action1
            Caption = '&Action1'
          end
          item
            Items = <
              item
                Action = Action2_1
              end
              item
                Action = Action2_2
              end>
            Action = Action2
            Caption = 'A&ction2'
          end>
        ActionBar = ActionMainMenuBar1
      end
      item
        Items = <
          item
            Action = Action2_1
          end
          item
            Action = Action2_2
          end>
      end>
    Left = 8
    Top = 40
    StyleName = 'XP Style'
    object Action1: TAction
      Caption = 'Action1'
      OnExecute = emptyActionHandler
    end
    object Action1_1: TAction
      Category = 'ac1'
      Caption = 'Action1_1'
      OnExecute = emptyActionHandler
    end
    object Action1_2: TAction
      Category = 'ac1'
      Caption = 'Action1_2'
      OnExecute = emptyActionHandler
    end
    object Action2: TAction
      Caption = 'Action2'
      OnExecute = emptyActionHandler
    end
    object Action2_1: TAction
      Category = 'ac2'
      Caption = 'Action2_1'
      OnExecute = emptyActionHandler
    end
    object Action2_2: TAction
      Category = 'ac2'
      Caption = 'Action2_2'
      OnExecute = emptyActionHandler
    end
  end
end

0 个答案:

没有答案
相关问题