如何根据屏幕大小c#调整表单大小 [英] How to resize form according to Screen size c#

查看:109
本文介绍了如何根据屏幕大小c#调整表单大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小的窗口表格

宽度:900

高度:640

因此当我在正常窗口中加载表格时好吧,但是例如说我打开相同的窗体在较小的尺寸说宽度:800和高度:600,他们我的形式超过窗口的大小

所以我想要适合我的形式的大小相应地,





i也试过这段代码



this.StartPosition = FormStartPosition.Manual;

this.Location = new Point(0,0);

Size formSize = new Size(Screen.GetWorkingArea(this).Width,Screen.GetWorkingArea (这).Height);

this.Size = new Size(formSize.Width,formSize.Height);

I got a windows form with size say
width: 900
Height: 640
so when i load form in normal window its ok but for example say i open same form in windows with smaller size say width:800 und Height:600, them my form exceeds than the size of window
so i want to fit the size of my form accordingly,


i also tried this code

this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0);
Size formSize = new Size(Screen.GetWorkingArea(this).Width, Screen.GetWorkingArea(this).Height);
this.Size = new Size(formSize.Width, formSize.Height);

推荐答案

Don' t。

要么设计较小的尺寸,要么让用户拿出滚动条。

Winforms应用程序不会自动缩放:所以改变窗口的大小不会改变控件的大小或它们上面的文本,a d虽然使用Dock和Anchor属性自动调整控件的大小相对容易,但这只会影响控件的总大小 - 它不会影响按钮上的文本或它们包含的控件的高度。所以你最终得到的按钮太小而没有传说,或者在中间用小字母取消这个词。



有设计它可以工作 - VS是一个 - 但它们必须从头开始设计 - 并且有一个最小尺寸,即使它们也可以工作!
Don't.
Either design for the smaller size, or let the user put up with scroll bars.
Winforms applications don't scale automatically: so changing the size of the window doesn't alter the size of the controls or the text on them, and while it is relatively easy to resize the controls automatically using the Dock and Anchor properties, that only affects the total size of the control - it doesn't affect the text on buttons, or the height of controls they contain. So what you end up with is buttons too small to have a legend, or with the word "Cancel" in tiny letters in the middle.

There are designs where it can work - VS is one - but they have to be designed for that from the ground up - and there is a "minimum size" at which even they will work!


OriginalGriff wrote: "Winforms applications don't scale automatically: so changing the size of the window doesn't alter the size of the controls or the text on them" 

我必须采取异常对此:如果您仔细设计Windows窗体,使用面板和其他容器控件,对所有顶级窗体控件,并仔细设置控件属性,如'Dock,'锚点,'边距',填充,'AutoSize,'AutoSizeMode。 ..



随着表格大小的改变,您可以获得相当不错的视觉重新调整大小;当然,正如OriginalGriff指出的那样,FontSize不会自动缩放,如果您自己重新缩放FontSize,很可能在任何给定的任意比例尺寸下都不会得到好看的结果,因为字体中使用的光学提示在小尺寸保证时,它们仅在某些离散尺寸上看起来最佳。位图是另一种情况,其中任意重新调整大小可能会导致可怕的视觉效果。



而且,在不同分辨率的显示器上获得Windows窗体真的很好看也是如此很多工作,可能需要,实际上,根据屏幕宽高比实际预先计算尺寸。



如果你真的想要动态重新调整大小,你会是最好使用WPF。



如果你想要追求这个,你需要检查'WinForms中的Screen类,并熟悉它的对象,喜欢' PrimaryScreen,熟悉控件属性,如'DisplayRectangle和'ClientRectangle。

I have to take exception to this: if you carefully design your Windows Form, using Panels and other Container Controls, for all top-level Form Controls, and carefully set Control Properties like 'Dock, 'Anchor, 'Margin, 'Padding, 'AutoSize, 'AutoSizeMode ...

You can get fairly good visual re-sizing as the Form Size is changed; of course, as OriginalGriff points out, FontSize will not scale automatically, and if you did take on re-scaling FontSize yourself, chances are you will not get good-looking results at any given arbitrary scale size because the optical-hinting used in Fonts at small sizes "guarantees" they only look best at certain discrete sizes. Bitmaps are another case where arbitrary re-sizing may result in terrible visuals.

And, it's also true that getting a Windows Form to really look good on different resolution monitors can be a lot of work, requiring, possibly, actually pre-computing sizes based on screen aspect ratios.

If you really want dynamic re-sizing, you'd be better off using WPF.

If you are going to pursue this, you need to examine the 'Screen class in WinForms, and become familiar with its objects, lik e'PrimaryScreen, and familiar with Control Properties like 'DisplayRectangle, and 'ClientRectangle.


这篇关于如何根据屏幕大小c#调整表单大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆