我想從控制檯使用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. Process.WaitForExit()在控制檯VS Windows窗體
- 3. C#Windows窗體.Net和DOS控制檯
- 4. 窗體和控制檯
- 5. 隱藏Windows窗體應用程序中的控制檯窗口
- 6. Windows窗體和控制檯之間的溝通
- 7. C#Windows窗體:用於製表控制
- 8. Windows窗體曲線/小區的控制
- 9. Windows控制檯
- 10. 從控制檯在Windows窗體中使用一個變量
- 11. 從Windows窗體運行控制檯應用程序
- 12. 從控制檯應用程序到Windows窗體GUI問題
- 13. 從控制檯應用程序到.NET Windows窗體
- 14. 在Windows窗體中嵌入DOS控制檯
- 15. 我可以從控制檯程序啓動Windows窗體
- 16. Windows窗體VS控制檯應用程序
- 17. 將控制檯appender添加到log4net中的窗體窗體
- 18. 連接一個窗體與控制檯
- 19. .NET:Windows窗體+控制檯/合閘閉鎖
- 20. Windows窗體控件
- 21. Windows窗體的Windows XP控制面板控件
- 22. C#Windows窗體控制圖像?
- 23. 用戶控制單擊 - Windows窗體
- 24. 如何從Windows窗體應用程序在C#中關閉控制檯窗口?
- 25. Windows控制檯API
- 26. 日曆控制使用系統Windows窗體日曆C#Windows窗體
- 27. 控制PowerShell控制檯窗口位置
- 28. Windows窗體拖動控件
- 29. 試圖將控制檯應用程序轉換爲VS 2012中的Windows窗體
- 30. 如何關閉窗體後關閉控制檯窗口
我可以在downmods上得到一些評論嗎? – 2009-10-26 20:09:26
爲什麼這是低調?這可能不是很好的做法,但它絕對有可能。 – 2009-10-26 20:09:58
這個工作沒有STAThread屬性嗎? – 2009-10-26 20:15:41