屏幕分辨率更改时Zom Out出现故障 [英] Zom Out malfunctions when Screen resolution changes

查看:103
本文介绍了屏幕分辨率更改时Zom Out出现故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在使用UserControl来显示图片。我的应用程序具有放大/缩小功能。我可以按任何

次数的缩小按钮,我写的背景代码将确保图片的左侧不会离开
$ b $的左侧b用户控件是在它上面绘制的。此逻辑仅适用于单个分辨率。无论设备分辨率如何,我都可以使这个逻辑工作吗?

Hi. I am using a UserControl to display a picture. My application has a Zoom In/Zoom Out feature. I can press the Zoom Out button any
number of times and the background code I write will make sure that the left side of the picture would not leave the left side of the
UserControl it is drawn up on. This logic works fine only for a single resolution. Can I make this logic work irrespective of the device resolution?

推荐答案

我已经完成了这个与屏幕无关的布局(有和没有缩放)多次,从来没有遇到过问题。

您可以查看几个简单的规则。



查看您的设计时生成的表单代码(作为C#源代码)并查找所有立即数的整数类型常量。您不应该找到定义任何控件的大小或位置的单个。排除项包括:字体大小,表单大小 - 当前和最小/最大 - 以及填充。换句话说,所有控件都应使用填充进行停靠和对齐。你应该做另一个简单的检查:彻底改变你的表格宽度/高度 - 布局应该保持其理智。如果您应保留某些元素的宽高比,则应在调整大小事件中执行正确的重新计算。永远不要使用锚点 - 不仅它们使用常量,它们还会在调整大小时引起一些闪烁。如果您观察到这一切,您的布局将容忍屏幕尺寸。



此外,您可以选择屏幕在显示之前按比例调整大小和更改表单大小。 (你可以在表单构造函数的最后一行调用一些函数,并调用 InitializeComponent()



忘记intellisense:什么,难以看到源代码(来自元数据)或帮助?顺便说一下,没有 SetDockStyle ,有属性 Dock - 不要怪你的智能感知。



替代建议:切换到WPF所有问题都已经得到很好的解决,包括缩放和宽高比。而且,与表格相比,性能太优越了。



祝你好运。

-SA
I've done this screen-independent layout (with and without zoom) many times and never had problems.
There are few simple rules you can check.

Look at your design-time generated form code (as C# source) and find all immediate constants of integer types. You should not find a single one that defined a size or location of any controls. Exclusions are: font size, form size — current and minimum/maximum — and padding. In other words, all controls should be docked and aligned using padding. You should do another simple check: change your form width/height drastically — layout should keep its sanity. If you should preserve aspect ratio of some elements, you should perform proper re-calculations in Resize event. Never use anchors — not only they use constants, they also tend to cause some flicker in resize. If you observe all this, you layout will tolerate screen size.

Additionally and optionally, you can read Screen size and change form size proportionally before you show it. (You can call some function with all adjustments and settings in a last line of the form constructor (right after a call to InitializeComponent()).

Forget about intellisense: what, is it difficult to see source code (from meta-data) or Help? By the way there is not SetDockStyle, there is the property Dock — don't blame your intellisense.

Alternative advice: switch to WPF, where all that problems are already well solved, including zoom and aspect ratio. Also, performance is way too superior compared to Forms.

Good luck.
—SA


这篇关于屏幕分辨率更改时Zom Out出现故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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