Share via


How to: Create a Ribbon Panel and Button

The following code example creates a custom Ribbon panel and button. When a user selects the associated report view in PerformancePoint Dashboard Designer, the button is enabled on the Ribbon.

using System.Windows.Forms;
using CustomPlugin.Properties;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework.Controls;
using Microsoft.PerformancePoint.Scorecards.Modeler.Framework.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
//using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.ReportViews;

namespace CustomPlugin
{
    public class CustomPluginPanel : OfficeRibbonPanel
    {
        public static string PanelId = "CustomPluginPanel";

        public override bool ShouldShow
        {
            get
            {
                ToolStripButton button = MainForm.GetInstance().OfficeRibbonTab.GetTabButton(CustomPluginFactory.CustomPluginTabId);

                    if (ScorecardModel.GetInstance().ReportViewsInWorkspace.Count > 0)
                    {
                        ReportView customReportView = ScorecardModel.GetInstance().ReportViewsInWorkspace[MainForm.GetInstance().SelectedWorkspaceItem.WorkspaceId];

                        // Make the button visible when the focus is on your custom report view.
                        if (customReportView != null && customReportView.TypeName == CustomPluginFactory.CustomReportName)
                        {
                            if (button != null)
                            {
                                button.Visible = true;
                            }
                            return true;
                        }
                    }
                    return false;
                }
            }

            public CustomPluginPanel()
            {
                base.Title = "Test Panel";
                base.Id = PanelId;
                base.ContextSensitive = true;
                base.TabId = RibbonUtilities.OfficeRibbonTabEdit;
                base.Visible = true;

                OfficeRibbonButton officeRibbonButton = new OfficeRibbonButton();                    
                officeRibbonButton.Text = "Test Button";
                officeRibbonButton.Image = Resources.CustomPlugin;
                officeRibbonButton.Visible = true;

                this.Controls.Add(officeRibbonButton);
            }
        }
    }

See Also

Tasks

How to: Install a Ribbon Extension

Concepts

How to: Create a Report Wizard Template
How to: Create a Ribbon Tab

Other Resources

Ribbon Items