我想从控制台使用C#生成Windows窗体。大致像display
在Linux中所做的那样,并修改其内容等。这可能吗?控制台的Windows窗体
5
A
回答
6
您应该能够添加引用了System.Windows.Forms的,然后是好去。您可能还必须将STAThreadAttribute应用于应用程序的入口点。
using System.Windows.Forms;
class Program
{
[STAThread]
static void Main(string[] args)
{
MessageBox.Show("hello");
}
}
...更复杂......
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();
}
}
4
是的,你可以在控制台中初始化一个表单。添加到System.Windows.Forms的一个参考,使用下面的示例代码:
System.Windows.Forms.Form f = new System.Windows.Forms.Form();
f.ShowDialog();
1
你可以试试这个
using System.Windows.Forms;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MyForm());
}
再见。
4
常见的答案:
[STAThread]
static void Main()
{
Application.Run(new MyForm());
}
替代品(从here拍摄)如果,例如 - 你想从比主应用程序的线程上推出的一种形式:
Thread t = new Thread(new ThreadStart(StartNewStaThread));
// Make sure to set the apartment state BEFORE starting the thread.
t.ApartmentState = ApartmentState.STA;
t.Start();
private void StartNewStaThread() {
Application.Run(new Form1());
}
。
Thread t = new Thread(new ThreadStart(StartNewStaThread));
t.Start();
[STAThread]
private void StartNewStaThread() {
Application.Run(new Form1());
}
相关问题
- 1. C#中的控制台和Windows窗体#
- 2. C#Windows窗体.Net和DOS控制台
- 3. Process.WaitForExit()在控制台VS Windows窗体
- 4. 产生窗体(Windows窗体)的控制台应用程序?
- 5. 窗体和控制台
- 6. 隐藏Windows窗体应用程序中的控制台窗口
- 7. 性能差异C++,使用Windows窗体与Windows控制台
- 8. Windows窗体和控制台之间的沟通
- 9. 在Windows窗体中创建像UI一样的控制台
- 10. C#Windows窗体:用于制表控制
- 11. Windows控制台
- 12. Windows窗体曲线/小区的控制
- 13. 从控制台应用程序到.NET Windows窗体
- 14. 保持一个控制另一台总是在Windows窗体.NET
- 15. 在Windows窗体中嵌入DOS控制台
- 16. 从Windows窗体应用程序C控制台应用程序#
- 17. 我可以从控制台程序启动Windows窗体
- 18. Windows窗体VS控制台应用程序
- 19. 从Windows窗体运行控制台应用程序
- 20. 使Windows窗体应用程序块控制台
- 21. 从控制台应用程序到Windows窗体GUI问题
- 22. 与控制台应用程序Windows窗体应用程序
- 23. 从控制台在Windows窗体中使用一个变量
- 24. 将控制台appender添加到log4net中的窗体窗体
- 25. 连接一个窗体与控制台
- 26. .NET:Windows窗体+控制台/合闸闭锁
- 27. 显示在Windows窗体应用程序中的控制台窗口
- 28. Windows窗体控件
- 29. Windows窗体的Windows XP控制面板控件
- 30. 在窗体窗体应用程序控制台
我可以在downmods上得到一些评论吗? – 2009-10-26 20:09:26
为什么这是低调?这可能不是很好的做法,但它绝对有可能。 – 2009-10-26 20:09:58
这个工作没有STAThread属性吗? – 2009-10-26 20:15:41