功能区隐藏操作再次出现

时间:2014-06-03 13:17:56

标签: delphi delphi-xe2 ribbon vcl

我正在使用Delphi XE2。在我的程序的主窗口中,我有一个功能区,我创建了ribbontabs和功能区面板,并在组中共享。此外,在另一个窗口中,我有一个TreeView,我在其中为每个用户设置了对功能区的访问权限,为每个操作提供了两种可能性:隐藏或禁用。隐藏操作时会出现问题,我通过访问应用程序动态地执行此操作。最小化和最大化功能区隐藏操作再次出现时。

这是我的代码:

PAS:

    unit Example;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ToolWin, Vcl.ActnMan, Vcl.ActnCtrls,
  Vcl.Ribbon, Vcl.RibbonLunaStyleActnCtrls, Vcl.ActnList, Vcl.StdCtrls;

type
  TFormExample = class(TForm)
    ActionManagerExample: TActionManager;
    Ribbon1: TRibbon;
    RibbonPage1: TRibbonPage;
    RibbonPage2: TRibbonPage;
    RibbonGroup1: TRibbonGroup;
    RibbonGroup2: TRibbonGroup;
    RibbonGroup3: TRibbonGroup;
    RibbonGroup4: TRibbonGroup;
    Action1: TAction;
    Action2: TAction;
    Action3: TAction;
    Action4: TAction;
    Action5: TAction;
    Action6: TAction;
    Action7: TAction;
    Action8: TAction;
    Action9: TAction;
    Action10: TAction;
    ButtonClickMe: TButton;
    procedure ButtonClickMeClick(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Action2Execute(Sender: TObject);
    procedure Action3Execute(Sender: TObject);
    procedure Action4Execute(Sender: TObject);
    procedure Action5Execute(Sender: TObject);
    procedure Action6Execute(Sender: TObject);
    procedure Action7Execute(Sender: TObject);
    procedure Action8Execute(Sender: TObject);
    procedure Action9Execute(Sender: TObject);
    procedure Action10Execute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormExample: TFormExample;

implementation

{$R *.dfm}

procedure TFormExample.Action10Execute(Sender: TObject);
begin
  ShowMessage('Action 10');
end;

procedure TFormExample.Action1Execute(Sender: TObject);
begin
  ShowMessage('Action 1');
end;

procedure TFormExample.Action2Execute(Sender: TObject);
begin
  ShowMessage('Action 2');
end;

procedure TFormExample.Action3Execute(Sender: TObject);
begin
  ShowMessage('Action 3');
end;

procedure TFormExample.Action4Execute(Sender: TObject);
begin
  ShowMessage('Action 4');
end;

procedure TFormExample.Action5Execute(Sender: TObject);
begin
  ShowMessage('Action 5');
end;

procedure TFormExample.Action6Execute(Sender: TObject);
begin
  ShowMessage('Action 6');
end;

procedure TFormExample.Action7Execute(Sender: TObject);
begin
  ShowMessage('Action 7');
end;

procedure TFormExample.Action8Execute(Sender: TObject);
begin
  ShowMessage('Action 8');
end;

procedure TFormExample.Action9Execute(Sender: TObject);
begin
  ShowMessage('Action 9');
end;

procedure TFormExample.ButtonClickMeClick(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to ActionManagerExample.ActionCount - 1 do
  begin
    if ActionManagerExample.Actions[i] is TCustomAction then
      TCustomAction(ActionManagerExample.Actions[i]).Visible := False;
  end;
end;

end.

DFM

    object FormExample: TFormExample
  Left = 0
  Top = 0
  Caption = 'Example'
  ClientHeight = 356
  ClientWidth = 699
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Ribbon1: TRibbon
    Left = 0
    Top = 0
    Width = 699
    Height = 143
    ActionManager = ActionManagerExample
    Caption = 'SSCCE'
    Tabs = <
      item
        Caption = 'Page 1'
        Page = RibbonPage1
      end
      item
        Caption = 'Page 2'
        Page = RibbonPage2
      end>
    ExplicitLeft = 480
    ExplicitTop = 72
    ExplicitWidth = 0
    DesignSize = (
      699
      143)
    StyleName = 'Ribbon - Luna'
    object RibbonPage2: TRibbonPage
      Left = 0
      Top = 50
      Width = 698
      Height = 93
      Caption = 'Page 2'
      Index = 1
      object RibbonGroup3: TRibbonGroup
        Left = 4
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 3'
        GroupIndex = 0
      end
      object RibbonGroup4: TRibbonGroup
        Left = 62
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 4'
        GroupIndex = 1
      end
    end
    object RibbonPage1: TRibbonPage
      Left = 0
      Top = 50
      Width = 698
      Height = 93
      Caption = 'Page 1'
      Index = 0
      object RibbonGroup1: TRibbonGroup
        Left = 4
        Top = 3
        Width = 56
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 1'
        GroupIndex = 0
      end
      object RibbonGroup2: TRibbonGroup
        Left = 62
        Top = 3
        Width = 62
        Height = 86
        ActionManager = ActionManagerExample
        Caption = 'Group 2'
        GroupIndex = 1
      end
    end
  end
  object ButtonClickMe: TButton
    Left = 80
    Top = 200
    Width = 337
    Height = 97
    Caption = 'Click me and then minimize and maximize the ribbon'
    TabOrder = 1
    OnClick = ButtonClickMeClick
  end
  object ActionManagerExample: TActionManager
    ActionBars = <
      item
        Items = <
          item
            Action = Action1
            Caption = 'A&ction 1'
          end
          item
            Action = Action2
            Caption = '&Action 2'
          end
          item
            Action = Action3
            Caption = 'Ac&tion 3'
          end>
        ActionBar = RibbonGroup3
      end
      item
        Items = <
          item
            Action = Action4
            Caption = '&Action 4'
          end
          item
            Action = Action5
            Caption = 'A&ction 5'
          end
          item
            Action = Action6
            Caption = 'Ac&tion 6'
          end>
        ActionBar = RibbonGroup4
      end
      item
        Items = <
          item
            Action = Action7
            Caption = '&Action 7'
          end
          item
            Action = Action8
            Caption = 'A&ction 8'
          end
          item
            Action = Action9
            Caption = 'Ac&tion 9'
          end>
        ActionBar = RibbonGroup1
      end
      item
        Items = <
          item
            Action = Action10
            Caption = '&Action 10'
          end>
        ActionBar = RibbonGroup2
      end>
    Left = 528
    Top = 200
    StyleName = 'Ribbon - Luna'
    object Action1: TAction
      Caption = 'Action 1'
      OnExecute = Action1Execute
    end
    object Action2: TAction
      Caption = 'Action 2'
      OnExecute = Action2Execute
    end
    object Action3: TAction
      Caption = 'Action 3'
      OnExecute = Action3Execute
    end
    object Action4: TAction
      Caption = 'Action 4'
      OnExecute = Action4Execute
    end
    object Action5: TAction
      Caption = 'Action 5'
      OnExecute = Action5Execute
    end
    object Action6: TAction
      Caption = 'Action 6'
      OnExecute = Action6Execute
    end
    object Action7: TAction
      Caption = 'Action 7'
      OnExecute = Action7Execute
    end
    object Action8: TAction
      Caption = 'Action 8'
      OnExecute = Action8Execute
    end
    object Action9: TAction
      Caption = 'Action 9'
      OnExecute = Action9Execute
    end
    object Action10: TAction
      Caption = 'Action 10'
      OnExecute = Action10Execute
    end
  end
end

任何人都知道如何保持隐藏状态?这部电影内部发生了什么让股票出现?

借口这个功能区给我带来很多问题并且有很多错误。但是想在我的工作中实施。 : - (

1 个答案:

答案 0 :(得分:2)

这似乎来自TCustomRibbonGroup.ShowControls(在Ribbon.pas中)。它循环遍历组中的控件,如果它不是TCustomToolScrollBtn的后代,则将每个控件设置为可见:

procedure TCustomRibbonGroup.ShowControls;
var
  I: Integer;
begin
  for I := 0 to ControlCount - 1 do
  begin
    if Controls[I] <> nil then
      Controls[I].Visible := not Controls[I].InheritsFrom(TCustomToolScrollBtn);
  end;
end;

我认为发生这种情况的原因是因为设计指南声明您不应该隐藏/显示组中的项目,而是应该启用/禁用它们并让用户看到它们不会出现在他们预期被发现的地方。从Microsoft Ribbon Guidelines强调添加):

  

禁用不适用于当前上下文或直接导致错误的命令。如果有用,请使用增强的工具提示来解释禁用该命令的原因。 不要隐藏此类命令,因为这样做会导致功能区布局发生变化,使功能区显示不稳定。