與 Visual Studio 中的其他工具窗口一樣,可以控制它的物理參數(shù),如大小、位置以及它是停靠的還是自由浮動(dòng)的。有關(guān)如何操作該工具窗口和其他 Visual Studio 工具窗口的信息,請(qǐng)參見如何:更改窗口特性。 “解決方案資源管理器”本身沒(méi)有自己的自動(dòng)化對(duì)象,但是可以使用 UIHierarchy 在一定程度上控制其層次結(jié)構(gòu)的內(nèi)容。若要控制解決方案中的項(xiàng)目和項(xiàng)目項(xiàng),請(qǐng)使用項(xiàng)目自動(dòng)化模型。有關(guān)更多信息,請(qǐng)參見控制項(xiàng)目和解決方案。注意顯示的對(duì)話框和菜單命令可能會(huì)與“幫助”中的描述不同,具體取決于您現(xiàn)用的設(shè)置或版本。這些過(guò)程是使用現(xiàn)用的常規(guī)開發(fā)設(shè)置開發(fā)的。若要更改設(shè)置,請(qǐng)?jiān)凇肮ぞ摺辈藛紊线x擇“導(dǎo)入和導(dǎo)出設(shè)置”。有關(guān)更多信息,請(qǐng)參見 Visual Studio 設(shè)置。使用UIHierarchy 控制解決方案資源管理器如果“解決方案資源管理器”不可見,請(qǐng)單擊“視圖”菜單上的“解決方案資源管理器”。 打開一個(gè)含有許多元素的項(xiàng)目,如外接程序項(xiàng)目。在“解決方案資源管理器”中單擊至少包含兩個(gè)子節(jié)點(diǎn)的節(jié)點(diǎn)。運(yùn)行以下代碼。C#VBusing System.Text; publicvoid OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; // Pass the applicationObject member variable to the code example. slnExplUIHierarchyExample(_applicationObject); } publicvoid slnExplUIHierarchyExample(DTE2 dte) { UIHierarchy UIH = dte.ToolWindows.SolutionExplorer; // Requires a reference to System.Text.// Set a reference to the first level nodes in Solution Explorer. // Automation collections are one-based. UIHierarchyItem UIHItem = UIH.UIHierarchyItems.Item(1); StringBuilder sb = new StringBuilder(); // Iterate through first level nodes.foreach ( UIHierarchyItem fid in UIHItem.UIHierarchyItems ) { sb.AppendLine(fid.Name); // Iterate through second level nodes (if they exist).foreach ( UIHierarchyItem subitem in fid.UIHierarchyItems ) { sb.AppendLine(" "+subitem.Name); // Iterate through third level nodes (if they exist).foreach ( UIHierarchyItem subSubItem in subitem.UIHierarchyItems ) { sb.AppendLine(" "+subSubItem.Name); } } } System.Windows.Forms.MessageBox.Show(sb.ToString()); } 請(qǐng)參見任務(wù)如何:創(chuàng)建外接程序演練:創(chuàng)建向?qū)Ц拍頥SProject2 對(duì)象介紹自動(dòng)化對(duì)象模型圖表其他資源創(chuàng)建和控制環(huán)境窗口創(chuàng)建外接程序和向?qū)ё詣?dòng)化與擴(kuò)展性參考