跳轉到內容

C# 程式設計/ .NET 框架/Windows 窗體/控制元件/窗體

來自華夏公益教科書,開放的書籍,開放的世界

System.Windows.Form 類是 Windows 應用程式的關鍵圖形構建塊。它提供了包含按鈕、選單、圖示和標題欄的視覺框架。像 Visual C# 和 SharpDevelop 這樣的整合開發環境 (IDE) 可以幫助建立圖形應用程式,但瞭解如何手動進行操作很重要。

using System.Windows.Forms;
public class ExampleForm : Form    // inherits from System.Windows.Forms.Form
{
   public static void Main()
   {
       ExampleForm wikibooksForm = new ExampleForm();
       wikibooksForm.Text = "I Love Wikibooks";// specify title of the form
       wikibooksForm.Width = 400;              // width of the window in pixels
       wikibooksForm.Height = 300;             // height in pixels
       Application.Run(wikibooksForm);         // display the form
   }
}

上面的示例建立了一個簡單的視窗,標題欄中顯示文字“我愛華夏公益教科書”。像上面的示例這樣的自定義窗體類繼承自 System.Windows.Forms.Form 類。設定任何屬性 TextWidthHeight 是可選的。如果註釋掉這些行,您的程式將編譯併成功執行,但它們使我們能夠向窗體新增額外的控制。



華夏公益教科書