简体   繁体   English

如何设置控件和表格大小以根据屏幕分辨率进行更改?

[英]How do i set the controls and the form size to change according to the screen resolution?

For example i just created a new Form i show him with a click button. 例如,我刚刚创建了一个新表单,然后单击按钮向他显示。

In the new form Designer i add 4 panels and docked them to the right left up down center. 在新的窗体设计器中,我添加了4个面板并将它们停靠在中心的左上角。

Then added on the bottom panel a button for the test. 然后在底部面板上添加测试按钮。

Now i did that on my screen resolution 1920X1080. 现在,我在屏幕分辨率1920X1080上做到了这一点。

But when i switched the resolution to 1024X768 the button seems to be ok but the form it self went out of bounds to the left and right. 但是,当我将分辨率切换为1024X768时,该按钮似乎还可以,但它本身的形式在左右两侧超出范围。

So how can i make that form will fit to the screen resolution changes ? 那么,如何使该表格适合屏幕分辨率的变化呢? I want the form to be full screen or not full screen but to fit the new resolution each time i change my monitor resolution. 我希望表单为全屏或非全屏形式,但是每次更改显示器分辨率时都要适应新的分辨率。

Not only the controls to fit but also the form if the form size was 170X120 so i dont want to change the form size but to fit him to the new resolution. 如果表单尺寸为170X120,不仅要适合控件,而且要适合表单,所以我不想更改表单尺寸,而是要适应新的分辨率。 I mean maybe i will have to change the size of the form but the idea is to keep the form how it was and fit him to the new resolution. 我的意思是也许我将不得不更改表格的大小,但其想法是保持表格的原状并使他适应新的决议。

One of the easiest ways to do it is to use percentages as opposed to pixel values. 最简单的方法之一是使用百分比而不是像素值。 Set the width of the form to 100% and each of the elements within them to 25% or whatever you need to fill the space. 将表单的宽度设置为100%,并将其中的每个元素设置为25%或填充空间所需的尺寸。 That's my initial stab at it without seeing any code. 那是我最初的尝试,没有看到任何代码。

You can use the anchor property to have controls adjust to the size of the window. 您可以使用anchor属性使控件调整为窗口大小。

Here is a great article on how to use the anchor: 这是一篇有关如何使用锚的出色文章:

http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/6165908 http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/6165908

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Windows窗体适合/重新调整为任何屏幕分辨率? - How do I fit/re-size Windows Form to any screen resolution? 根据屏幕分辨率将Windows窗体上的按钮控件调整为固定大小 - resize button controls on windows form to fixed size as per screen resolution WPF(如何设置不同尺寸PC的屏幕分辨率) - WPF(How can i set Screen resolution of different size of PC) 如何统一设置二维正交相机的边界以根据屏幕尺寸进行修改 - How do I set the boundaries of a 2d ortographic camera in unity to modify according to the screen size 如何保留int变量的旧值数量并根据行数更改form1的大小? - How do i keep the old value number of int variable and change the form1 size according to the number of rows? 更改表单大小后,如何自动调整控件的大小? - How do I resize the controls automatically when form size is changed? 跟踪Windows窗体应用程序中的屏幕更改和屏幕分辨率更改以更改表单大小 - Keep track of screen change and screen resolution change in Windows Form Application to change form size 如何随着分辨率的变化自动调整大小和调整表单控件 - How to auto resize and adjust Form controls with change in resolution 根据表单大小在窗体上定位控件 - positioning controls on a windows form according to the form size 如何更改PrintDialog表单的大小 - How Do I Change the Size Of A PrintDialog Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM