第 1 步:創建 Windows 表單應用專案Step 1: Create a Windows Forms App project

創建圖片檢視器時,第一步是創建 Windows 表單應用專案。When you create a picture viewer, the first step is to create a Windows Forms App project.

開啟 Visual Studio 2017Open Visual Studio 2017

  1. 在功能表列上,選擇 "檔 > 新專案 > "。On the menu bar, choose File > New > Project. 對話方塊看起來應該類似下列螢幕擷取畫面。The dialog box should look similar to the following screenshot.

    [新增專案] 對話方塊New project dialog
    [新增專案]****** 對話方塊New project dialog box

  2. "新專案" 對話方塊的左側,選擇Visual C#視覺化基本,然後選擇Windows 桌面On the left side of the New Project dialog box, choose either Visual C# or Visual Basic, and then choose Windows Desktop.

  3. 在專案範本清單中,選擇Windows 表單應用 (.NET 框架)。In the project templates list, choose Windows Forms App (.NET Framework). 將新表單命名為 PictureViewer,然後選擇 [確定]**** 按鈕。Name the new form PictureViewer, and then choose the OK button.

    注意

    如果您未看到 [Windows Forms 應用程式 (.NET Framework)]**** 範本,請使用 Visual Studio 安裝程式來安裝 [.NET 桌面開發]**** 工作負載。If you don't see the Windows Forms App (.NET Framework) template, use the Visual Studio Installer to install the .NET desktop development workload.

    Visual Studio 安裝程式中的 .NET 桌面開發工作負載.NET desktop development workload in the Visual Studio Installer

    如需詳細資訊,請參閱安裝 Visual Studio 頁面。For more information, see the Install Visual Studio page.

開啟 Visual Studio 2019Open Visual Studio 2019

  1. 在啟動視窗中,選擇 "創建新專案"。On the start window, choose Create a new project.

    檢視 [建立新專案] 視窗

  2. 在 [建立新專案]**** 視窗中,在搜尋方塊內輸入或鍵入 Windows FormsOn the Create a new project window, enter or type Windows Forms in the search box. 接下來,從 "專案類型"清單中選擇 "桌面"。Next, choose Desktop from the Project type list.

    應用專案類型篩選器後,為 C# 或 Visual Basic 選擇Windows 表單應用 (.NET 框架) 範本,然後選擇 "下一步"。After you apply the Project type filter, choose the Windows Forms App (.NET Framework) template for either C# or Visual Basic, and then choose Next.

    選擇 Windows 表單應用的 C# 或視覺化基本範本 (.NET 框架)

    注意

    如果看不到Windows 表單應用 (.NET Framework) 範本,則可以從 "創建新專案" 視窗安裝該範本。If you don't see the Windows Forms App (.NET Framework) template, you can install it from the Create a new project window. 在 [找不到您要找的資料嗎?]**** 訊息中,選擇 [安裝更多工具和功能]**** 連結。In the Not finding what you're looking for? message, choose the Install more tools and features link.

    [建立新專案] 視窗中「找不到您要尋找的項目嗎?」訊息的 [安裝更多工具和功能] 連結

    接下來,在 Visual Studio 安裝程式中選擇 .NET 桌面開發工作負載。Next, in the Visual Studio Installer, choose the Choose the .NET desktop development workload.

    Visual Studio 安裝程式中的 .NET Core 工作負載

    接下來,選擇 Visual Studio 安裝程式中的 [修改]**** 按鈕。After that, choose the Modify button in the Visual Studio Installer. 系統可能會提示您儲存工作,若收到提示,請依提示執行。You might be prompted to save your work; if so, do so. 接下來,選擇 [繼續]**** 以安裝工作負載。Next, choose Continue to install the workload.

  3. 在 [設定您的新專案]**** 視窗的 [專案名稱]**** 方塊中鍵入或輸入 PictureViewerIn the Configure your new project window, type or enter PictureViewer in the Project name box. 然後,選擇 "創建"。Then, choose Create.

Visual Studio 為您的應用創建解決方案。Visual Studio creates a solution for your app. 解決方案充當應用所需的所有專案和檔的容器。A solution acts as a container for all of the projects and files needed by your app. 本教學課程稍後將會詳細說明這些詞彙。These terms will be explained in more detail later in this tutorial.

關於 Windows 表單應用專案About the Windows Forms App project

  1. 開發環境包含三個視窗:主視窗、[方案總管]**** 和 [屬性]**** 視窗。The development environment contains three windows: a main window, Solution Explorer, and the Properties window.

    如果缺少這些視窗中的任何一個,則可以還原預設視窗佈局。If any of these windows are missing, you can restore the default window layout. 在功能表列上,選擇 "視窗 > 重置視窗佈局"。On the menu bar, choose Window > Reset Window Layout.

    您也可以使用功能表命令顯示視窗。You can also display windows by using menu commands. 在功能表列上,選擇 "查看 > 屬性視窗"或 "解決方案資源管理器"。On the menu bar, choose View > Properties Window or Solution Explorer.

    如果有任何其他視窗開啟,請選擇視窗右上角的 [關閉]**** (x) 按鈕將視窗關閉。If any other windows are open, close them by choosing the Close (x) button in their upper-right corners.

    • 主視窗:您將在這個視窗中進行大部分的工作,例如,使用表單和編輯程式碼。Main window In this window, you'll do most of your work, such as working with forms and editing code. 視窗在 [表單編輯器]**** 中顯示表單。The window shows a form in the Form Editor. 視窗頂端會出現 [起始頁]**** 索引標籤和 [Form1.cs [Design]]**** 索引標籤At the top of the window, the Start Page tab and the Form1.cs [Design] tab appear. (在 Visual Basic 中,索引標籤名稱的結尾是 .vb,而不是 .cs)。(In Visual Basic, the tab name ends with .vb instead of .cs.)
    • 主視窗:您將在這個視窗中進行大部分的工作,例如,使用表單和編輯程式碼。Main window In this window, you'll do most of your work, such as working with forms and editing code. 視窗在 [表單編輯器]**** 中顯示表單。The window shows a form in the Form Editor.
    • 方案總管視窗:在這個視窗中,您可以檢視和巡覽至方案中的所有項目。Solution Explorer window In this window, you can view and navigate to all items in your solution.

    如果您選擇一個檔案,[屬性]**** 視窗的內容會隨著變更。If you choose a file, the contents of the Properties window changes. 如果打開代碼檔(以C# 中的 .cs 結尾,在 Visual Basic 中以 .vb結尾),則將顯示代碼檔的代碼檔或設計器。If you open a code file (which ends in .cs in C# and .vb in Visual Basic), the code file or a designer for the code file appears. 設計工具是一個視覺化介面,您可以將控制項 (例如按鈕和清單) 加入該介面中。A designer is a visual surface onto which you can add controls such as buttons and lists. Visual Studio 表單的設計工具稱為 Windows Forms 設計工具For Visual Studio forms, the designer is called the Windows Forms Designer.

    • 屬性視窗:在這個視窗中,您可以變更在其他視窗中所選擇項目的屬性。Properties window In this window, you can change the properties of items that you choose in the other windows. 例如,如果您選擇 Form1,可以設定 Text 屬性變更其標題,也可以設定 Backcolor 屬性變更背景色彩。For example, if you choose Form1, you can change its title by setting the Text property, and you can change the background color by setting the Backcolor property.

      注意

      方案總管**** 中的第一行會顯示 [方案 'PictureViewer' (1 個專案)]****,表示 Visual Studio 已為您建立方案。The top line in Solution Explorer shows Solution 'PictureViewer' (1 project), which means that Visual Studio created a solution for you. 方案可以包含多個專案,不過,您將暫時使用只包含一個專案的方案。A solution can contain more than one project, but for now, you'll work with solutions that contain only one project.

  2. 在功能表列上,選擇 "全部保存檔 > Save All"。On the menu bar, choose File > Save All.

    作為替代方法,請選擇工具列上的"全部保存" 按鈕,如下圖所示。As an alternative, choose the Save All button on the toolbar, which the following image shows.

    [全部儲存] 工具列按鈕Save All toolbar button
    **保存所有****工具列按鈕Save All toolbar button

    Visual Studio 會自動填入資料夾名稱和專案名稱,然後將專案儲存在專案資料夾中。Visual Studio automatically fills in the folder name and the project name and then saves the project in your projects folder.

後續步驟Next steps

另請參閱See also