如何:將類別圖表新增到專案How to: Add class diagrams to projects

若要設計、編輯和重構類別及其他類型,請將類別圖加入至 C#、Visual Basic 或 C++ 專案。To design, edit, and refactor classes and other types, add a class diagram to your C#, Visual Basic, or C++ project. 若要在專案中視覺化程式碼的不同部分,請將多個類別圖加入至專案。To visualize different parts of the code in a project, add multiple class diagrams to the project.

您不能從跨多個應用程式共用程式碼的專案建立類別圖。You can't create class diagrams from projects that share code across multiple apps. 若要建立 UML 類別圖表,請參閱建立 UML 模組化專案和圖表To create UML class diagrams, see Create UML modeling projects and diagrams.

安裝類別設計工具元件Install the Class Designer component

若您尚未安裝類別設計工具元件,請遵循下列步驟安裝。If you haven't installed the Class Designer component, follow these steps to install it.

  1. 從 Windows [開始] 功能表開啟 Visual Studio 安裝程式,或從 Visual Studio 的功能表列選取 [工具] > [取得工具與功能]。Open Visual Studio Installer from the Windows Start menu, or by selecting Tools > Get Tools and Features from the menu bar in Visual Studio.

    Visual Studio 安裝程式隨即開啟。Visual Studio Installer opens.

  2. 選取 [個別元件] 索引標籤,然後向下捲動到 [程式碼工具] 分類。Select the Individual components tab, and then scroll down to the Code tools category.

  3. 選取 [類別設計工具],然後選取 [修改]。Select Class Designer and then select Modify.

    Visual Studio 安裝程式中的類別設計工具元件

    類別設計工具元件會開始安裝。The Class Designer component starts installing.

將空白類別圖表新增至專案Add a blank class diagram to a project

  1. 方案總管中,以滑鼠右鍵按一下專案節點,然後選擇 [新增] > [新增項目]。In Solution Explorer, right-click the project node and then choose Add > New Item. 或者按 Ctrl+Shift+AOr, press Ctrl+Shift+A.

    [新增項目] 對話方塊隨即開啟。The Add New Item dialog opens.

  2. 展開 [常用項目] > [一般],然後從範本清單中選取 [類別圖表]。Expand Common Items > General, and then select Class Diagram from the template list. 若是 Visual C++ 專案,請在 [公用程式] 分類中尋找類別圖表範本。For Visual C++ projects, look in the Utility category to find the Class Diagram template.

    Note

    若您沒有看到類別圖表範本,請遵循這些步驟安裝 Visual Studio 的類別設計工具元件。If you don't see the Class Diagram template, follow the steps to install the Class Designer component for Visual Studio.

    類別圖表會在類別設計工具中開啟,並在方案總管中顯示為副檔名為 .cd 的檔案。The class diagram opens in Class Designer and appears as a file that has a .cd extension in Solution Explorer. 您可以從 [工具箱] 將圖形和線條拖曳到圖表。You can drag shapes and lines to the diagram from Toolbox.

若要加入多個類別圖,請重複本程序的步驟。To add multiple class diagrams, repeat the steps in this procedure.

根據現有類型新增類別圖表Add a class diagram based on existing types

在 [方案總管] 中,開啟類別檔案的快顯功能表 (以滑鼠右鍵按一下),然後選擇 [檢視類別圖表]。In Solution Explorer, open a class file's context menu (right-click) and then choose View Class Diagram.

-或--or-

在 [類別檢視] 中,開啟命名空間或類型操作功能表,然後選擇 [檢視類別圖表]。In Class View, open the namespace or type context menu and then choose View Class Diagram.

Tip

如果未開啟 [類別檢視],請從 [檢視] 功能表開啟 [類別檢視]。If Class View is not open, open Class View from the View menu.

在類別圖表中顯示完整專案的內容To display the contents of a complete project in a class diagram

在 [方案總管] 或 [類別檢視] 中,在專案上按一下滑鼠右鍵並選擇 [檢視],然後選擇 [類別圖表檢視]。In Solution Explorer or Class View, right-click the project and choose View, then choose View Class Diagram.

就會建立會自動填入內容的類別圖表。An auto-populated class diagram is created.

Note

類別設計工具尚無法於 .NET Core 專案中使用。Class Designer is not available in .NET Core projects.

請參閱See also