2017-01-23 46 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或创建一个具有您正在查找的所有属性的类,并使该函数的返回类型。