强制 .NetCF 1.0 缩放模型到 .NetCF 2.0 应用程序
我有一个在 .Net Compact Framework 1.0 中开发的大型应用程序,该应用程序是在过去 9 年中开发的,包含大量表单和自定义控件。该应用程序专为 240x320 屏幕设计。使用 Compact .Net 1.0 和 Visual Studio 2003 编译时,它可以很好地缩放到 480x640 屏幕。
我使用 Visual Studio 2008 的默认升级向导将应用程序升级到 .Net 2.0。应用程序使用全屏,所有控件均已布局按照使用分辨率为 240x320 的设备时的设计。但当使用分辨率为 480x640 的设备时,该应用程序仅使用屏幕左上角 25% 的区域。
我尝试使用代码: AutoScaleDimensions = 新 SizeF(96,96); AutoScaleMode = AutoScaleMode.Dpi;
它适用于表单,但不适用于放置在表单上的动态控件(标准/自定义)。
有没有办法强制应用程序使用类似于使用 .Net 1.0 编译时所做的缩放,而不使用 AutoScaleDimensions/AutoScaleMode 属性。
谢谢。
I have an large application developed in .Net Compact Framework 1.0 that has been developed over the last 9 years with large amount of forms and custom controls. The application is designed for 240x320 screens. It scales good to a 480x640 screen when compiled with Compact .Net 1.0 and Visual Studio 2003.
I upgraded the application to .Net 2.0 using the default upgrade wizard of Visual Studio 2008. The application uses the full screen and all the controls are laid out as designed when using a device with resolution of 240x320. But the application uses only top left 25% of the screen when using a device with resolution of 480x640.
I tried using the code:
AutoScaleDimensions = new SizeF(96,96);
AutoScaleMode = AutoScaleMode.Dpi;
It works on the Form, but does not work on the dynamic controls (standard/custom) that are placed on the form.
Is there a way to force the application to use scaling similar to that done when complied using .Net 1.0, with out using the AutoScaleDimensions/AutoScaleMode properties.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您创建自定义控件的代码包含硬编码值,这些值假定特定的 DPI(可能是设计者使用的 96)。
可以使用类似以下内容来分析运行应用程序的设备的主机分辨率:
您 在创建动态控件的代码中硬编码坐标,以使用计算出的scaleFactor调整值,例如:
In sounds like your code to create custom controls contains hard coded values that assume a particular DPI, probably of the designer used, 96.
You could analyse the host resolution of the device your application is running on using something like:
You would then modify any hard coded co-ordinates in your code that is creating the dynamic controls to adjust the values with the calculated scaleFactor, for example:
我找到了解决这个问题的方法。
我得到的比例因子类似于 simons19 然后,当向表单添加任何动态创建的控件时,我调用方法 control.Scale(scale-factor)。这解决了我的问题。 Scale 方法会缩放控件的位置和大小,因此,我在调用缩放属性之前设置动态创建的控件的位置属性和大小属性。
例子:
I found a kind of solution to this problem.
I get the scale-factor similar to the procedure explained by simons19 and then when adding any dynamically created control to the form, I call the method control.Scale(scale-factor). This solved my problem. Scale method scales both Location and Size of the control so, I set both location property and size property of the dynamically created control before calling the scale property.
Example: