在不同的DPIs - c#下向窗体添加控件(trackbars、多行文本框和标签)

时间:2022-02-18 14:46:29

My application loads information from a file which then creates x amount of controls on y amounts of tabpages in a form.

我的应用程序从一个文件中加载信息,该文件然后在表单中创建y数量的选项卡上的x数量的控件。

My problem is that when the user has a different DPI to the standard Windows 96, the controls added overlap each other. The initial controls on the form are fine.

我的问题是,当用户的DPI与标准的Windows 96不同时,添加的控件相互重叠。表单上的初始控件很好。

How can I set the controls to be modified to the 96 DPI instead of whatever the users machine is running at?

如何将控件设置为96 DPI而不是用户机器正在运行的位置?

If this is very difficult, is there a way to see what the users DPI is? I can then throw a warning saying that you should use 96DPI etc etc.

如果这是非常困难的,是否有办法查看用户DPI是什么?然后我可以发出警告说你应该使用96DPI等等。

Thank you for any help or advise you can give me!

谢谢你给我的任何帮助或建议!

2 个解决方案

#1


1  

I assume you use Windows.Forms. You can use property AutoScaleMode to control how each GUI control is zoomed. There are more options you can choose, so go and try what is best for you or you can also read this article in MSDN to get more information on principles of zooming of controls in Windows.Forms.

我猜你用的是Windows.Forms。您可以使用属性AutoScaleMode来控制每个GUI控件的缩放方式。你可以选择更多的选项,所以去试试什么对你来说是最好的,或者你也可以在MSDN上阅读这篇文章,以获得更多关于窗口控件缩放原则的信息。

#2


0  

Just to answer my own question I wrote this and put it in my Form load event:

为了回答我自己的问题,我写了这个,并把它放在我的表单加载事件中:

        Graphics formGraphics = this.CreateGraphics();
        if ((formGraphics.DpiX != 96) || (formGraphics.DpiY != 96))
        {
            MessageBox.Show("You are attempting to run this application in an unknown DPI. This application has been designed for Normal size (96 DPI), you may experience some display issues if you continue to use your current settings. Please change your Display settings back to normal size through your control panel to ensure you don't experience any problems. Thank you.",
            "Warning",
            MessageBoxButtons.OK,
            MessageBoxIcon.Exclamation,
            MessageBoxDefaultButton.Button1);
        }

#1


1  

I assume you use Windows.Forms. You can use property AutoScaleMode to control how each GUI control is zoomed. There are more options you can choose, so go and try what is best for you or you can also read this article in MSDN to get more information on principles of zooming of controls in Windows.Forms.

我猜你用的是Windows.Forms。您可以使用属性AutoScaleMode来控制每个GUI控件的缩放方式。你可以选择更多的选项,所以去试试什么对你来说是最好的,或者你也可以在MSDN上阅读这篇文章,以获得更多关于窗口控件缩放原则的信息。

#2


0  

Just to answer my own question I wrote this and put it in my Form load event:

为了回答我自己的问题,我写了这个,并把它放在我的表单加载事件中:

        Graphics formGraphics = this.CreateGraphics();
        if ((formGraphics.DpiX != 96) || (formGraphics.DpiY != 96))
        {
            MessageBox.Show("You are attempting to run this application in an unknown DPI. This application has been designed for Normal size (96 DPI), you may experience some display issues if you continue to use your current settings. Please change your Display settings back to normal size through your control panel to ensure you don't experience any problems. Thank you.",
            "Warning",
            MessageBoxButtons.OK,
            MessageBoxIcon.Exclamation,
            MessageBoxDefaultButton.Button1);
        }