[英]Why does my Windows-Forms Layout change, when I am opening it from a Console-Application?
At the beginning of my Project I am starting a Console.在我的项目开始时,我正在启动一个控制台。 After the Console executes my code, a new Form gets open.控制台执行我的代码后,会打开一个新表单。 The Problem the Form looks really strange, not like i designed it in the Editor.问题表单看起来很奇怪,不像我在编辑器中设计的那样。
Form in the Editor, like i designed:编辑器中的表格,就像我设计的那样:
Form after I opened it from the Console-Project:我从控制台项目打开它后的表格:
Code in the Console-Project for opening the Form控制台项目中用于打开表单的代码
Application.Run(new Form1());
One more thing: I am using .NET Core 3.1还有一件事:我正在使用 .NET Core 3.1
Anyone has a solution to this problem?有人有解决这个问题的方法吗?
thanks in advance!提前致谢!
If you want the same "theme" you should EnableVisualStyles as the first line in your main
method.如果您想要相同的“主题”,您应该将EnableVisualStyles作为main
方法的第一行。 As outlined in the documentation.如文档中所述。
Also call SetCompatibleTextRenderingDefault with false
as this is also the default since 2005.还调用SetCompatibleTextRenderingDefault并设置为false
,因为这也是自 2005 年以来的默认设置。
The following are the defaults when creating a new winforms project for dotnet core 3.1以下是为 dotnet core 3.1 创建新 winforms 项目时的默认设置
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.