WindowsFormsfromConsoleWindowsFormsfromConsole我想使用C#从控制台生成Windows窗体。大致类似于linux中的显示,修改其内容等是否可以?您应该能够添加对System.Windows.Forms的引用并且一切顺利。您可能还必须将STAThreadAttribute应用于应用程序的入口点。使用System.Windows.Forms;类程序{[STAThread]staticvoidMain(string[]args){MessageBox.Show("hello");}}...更复杂...使用System.Windows.Forms;类程序{[STAThread]staticvoidMain(string[]args){varfrm=newForm();frm.Name="你好";varlb=新标签();lb.Text="HelloWorld!!!";.添加(磅);frm.ShowDialog();}}是的,您可以在控制台中初始化表单。添加对System.Windows.Forms的引用并使用以下示例代码:System.Windows.Forms.Formf=newSystem.Windows.Forms.Form();f.ShowDialog();常见答案:[STAThread]staticvoidMain(){Application.Run(newMyForm());替代方案(取自此处),例如-您想要从主应用程序以外的线程启动表单:Threadt=newThread(newThreadStart(StartNewStaThread));//确保在启动线程之前设置单元状态。t.ApartmentState=ApartmentState.STA;t.开始();privatevoidStartNewStaThread(){Application.Run(newForm1());}。线程t=新线程(新线程开始(StartNewStaThread));t.开始();[STAThread]privatevoidStartNewStaThread(){Application.Run(newForm1());您可以尝试使用System.Windows.Forms;[STAThread]staticvoidMain(){Application.EnableVisualStyles();应用程序运行(新的MyForm());}再见。以上就是C#学习教程:控制台Windows形式分享的全部内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
