[英]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.