[英]Create a form in c#
我可以從控制台應用程序創建表單嗎? 如果是,那怎么辦?
是的你可以。
您需要引用System.Windows.Forms
程序集並將命名空間添加到您的代碼中。
您將沒有設計器支持,並且必須手動創建和添加控件等...
如果您已經在另一個程序集中有一個准備好的表格 class,您可以使用它,只需按照相同的步驟(添加引用、添加命名空間、新建和顯示)。
添加對 System.Windows.Forms 的引用,然后導入它的命名空間。 然后您可以創建 forms。
如果您關於動態表單創建的問題只需遵循Oded
和AtoMerZ
提供的答案。 如果您想使用圖形設計師創建它,只需在您的控制台項目中添加 Windows 表單,所有引用都會自動添加到項目中
是的。 和靈魂:
真的很清楚。
您需要在第一步中添加System.Windows.Forms
。如果您不知道如何打開solution explorer
管理器,請右鍵單擊references
,然后add reference
。 在出現的對話框和.Net tab
中 select System.Windows.Forms
從列表中單擊確定。
那么這是一個示例代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
System.Windows.Forms.Form MyForm = new System.Windows.Forms.Form();
System.Windows.Forms.Application.Run(MyForm);
}
}
}
我想你可能需要一本 c# 書。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.