简体   繁体   English

当我从控制台应用程序打开它时,为什么我的 Windows 窗体布局会发生变化?

[英]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.

相关问题 知道为什么这个计算器的控制台应用程序不起作用吗? - Any Idea why this calculator Console-Application does not work? C#控制台应用程序-如何在Windows下合并进程 - c# console-application - how to unite processes under windows 安全退出控制台应用程序? - Safely exit console-application? 将控制台应用程序中的文本记录到另一个项目中的RichTextBox中 - log text from a console-application to a richtextbox in another project 为什么从Windows Forms应用程序调用批处理文件时不复制文件,而在Console应用程序中却可以工作? - Why does the batch file not copy files when invoked from Windows Forms app but it works from Console app? 从Windows Forms应用程序打开WPF窗口时缺少图像 - Missing images when opening a wpf window from a windows forms application 从Windows窗体访问asmx服务给出最大请求长度错误 - Accessing a asmx service from windows-forms gives max request length error 如何使用请求后的Windows窗体打开网站? - How to open web-site from windows-forms using post-request? 从Windows窗体应用程序打开AutoCAD - Opening AutoCAD from Windows Forms Application 为什么关闭以AllocConsole启动的控制台会导致我的整个应用程序退出? 我可以改变这种行为吗? - Why does closing a console that was started with AllocConsole cause my whole application to exit? Can I change this behavior?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM