Windows窗体从控制台 [英] Windows form from console

查看:137
本文介绍了Windows窗体从控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从控制台使用C#生成一个Windows窗体。大概就像显示在Linux中,并修改其内容等是可能吗?

I would like to spawn a Windows form from the console using C#. Roughly like display does in Linux, and modify its contents, etc. Is that possible?

推荐答案

你应该能够为System.Windows.Forms添加一个引用,然后很好去。您可能还必须将STAThreadAttribute应用于应用程序的入口点。

You should be able to add a reference for System.Windows.Forms and then be good to go. You may also have to apply the STAThreadAttribute to the entry point of your application.

using System.Windows.Forms;

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        MessageBox.Show("hello");
    }
}

...更复杂...

... more complex ...

using System.Windows.Forms;

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        var frm = new Form();
        frm.Name = "Hello";
        var lb = new Label();
        lb.Text = "Hello World!!!";
        frm.Controls.Add(lb);
        frm.ShowDialog();
    }
}

这篇关于Windows窗体从控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆