Create a form in c#
Can I create开发者_JAVA技巧 a form from a console application? If yes then how?
Yes, you can.
You need to reference the System.Windows.Forms
assembly and add the namespace to your code.
Then you new up a Form
and Show
it.
You will not have designer support and will have to manually create and add controls etc...
If you already have a ready form class in another assembly, you could use that, simply following the same steps (add reference, add namespace, new up and show).
Add reference to System.Windows.Forms, and then import it's namespace. Then you can create forms.
If your question about dynamic form creation just folow answer provided by Oded
and AtoMerZ
. If you want create it with graphic designer just add Windows form in your console project and all references would added to project automaticaly
Yes. and the soultion:
It is realy so clear.
You need to add System.Windows.Forms
in first step.If you don't know how just open the solution explorer
right click on references
and then add reference
. In the dialog that apears and in .Net tab
select System.Windows.Forms
from list and click ok.
then this is a sample code
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);
}
}
}
I think you may need a c# book. :)
精彩评论