How to connect a ribbon button to a function defined in an Excel add-in?

你离开我真会死。 提交于 2019-12-22 17:57:58

问题


I'm using MSVS 2013 to create a C# MS Excel Add-In. In previous add-in paradigms, the ribbon class designer directly connected a ribbon button click event to function in the Add-In application class - now the ribbon functions are defined in the ribbon class, itself. What is the best way to access a function defined in the ThisAddIn class from the separate ribbon control class?


回答1:


This is a simple method for doing this:

    private void butRefreshSelectedWorksheets_Click(object sender, RibbonControlEventArgs e)
    {
        try
        {
            Globals.ThisAddIn.RefreshWorksheetListings();
        }
        catch (Exception ex)
        {
            System.Windows.Forms.MessageBox.Show("Error [butRefreshSelectedWorksheets_Click]: " + ex);
        }
    }

Use the Globals.ThisAddIn.... syntax to access app functions from within the ribbon.



来源:https://stackoverflow.com/questions/25043945/how-to-connect-a-ribbon-button-to-a-function-defined-in-an-excel-add-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!