2017-01-23 51 views
-1

在我的Excel加載項中,我創建了兩個任務窗格 - 每個窗格的可見性來自兩個不同的值,但都需要在return語句中將只允許我返回其中的一個值。這些是'taskPaneValue'和'taskPaneValue2'。在C#'get'語句中返回多個變量

我該如何解決'get'語句中返回的問題。

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
    { 
     taskPaneControl2 = new FileChooser(); 
     taskPaneValue2 = this.CustomTaskPanes.Add(taskPaneControl2, "File Chooser"); 
     taskPaneValue2.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged); 

     taskPaneValue2.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating; 
     taskPaneValue2.Height = 600; 
     taskPaneValue2.Width = 600; 

     taskPaneValue2.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange; 

     //These three lines of code start by initiating the TaskPane control (namely aLaCarteMenu()) 
     //It then goes on to set the name of the menu "A La Carte Menu" which appears on the top left of the window before stating its visibility. 
     taskPaneControl1 = new aLaCarteMenu(); 
     taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "A La Carte Menu"); 
     taskPaneValue.VisibleChanged += 

     //The following four lines of code are used to display the visiblity of the AddIn. 
     //The docking position is set to float, with a resolution of 980x1920. This is designed for a 1080p screen, however still working on changing it to fit screens dynamically. 
     new EventHandler(taskPaneValue_VisibleChanged); 
     taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating; 
     taskPaneValue.Height = 980; 
     taskPaneValue.Width = 1920; 

     //This line of code sets the position to be restricted to what has been set above (floating). This allows for the pane to be moved around the screen, as well as to be resized. 
     //This stops the pane from locking on to the right, left, top or bottom sections of the Excel Window. 
     taskPaneValue.DockPositionRestrict = Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange; 


} 

private void taskPaneValue_VisibleChanged(object sender,  System.EventArgs e) 
    { 
     Globals.Ribbons.ManageTaskPaneRibbon.toggleButton1.Checked = taskPaneValue.Visible; 
     Globals.Ribbons.ManageTaskPaneRibbon.toggleButton2.Checked = taskPaneValue2.Visible; 

    } 

    public Microsoft.Office.Tools.CustomTaskPane TaskPane 
    { 
     get 
     { 
      return taskPaneValue2; 
     } 

    } 

最後的'get'語句是我希望返回這兩個變量的語句。

+2

您是否考慮過[Tuple](https://msdn.microsoft.com/en-us/library/dd268536(v = vs.110).aspx)或創建類型保存你可以創建和返回的兩個值? – itsme86

回答

1

使用Tuple或創建一個具有您正在查找的所有屬性的類,並使該函數的返回類型。