问题
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