强制 .NetCF 1.0 缩放模型到 .NetCF 2.0 应用程序

发布于 2024-09-26 20:56:21 字数 567 浏览 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深爱成瘾 2024-10-03 20:56:22

听起来您创建自定义控件的代码包含硬编码值,这些值假定特定的 DPI(可能是设计者使用的 96)。

可以使用类似以下内容来分析运行应用程序的设备的主机分辨率:

const float designResolution = 96.0f; 
float scaleFactor;

System.Drawing.Graphics g = f.CreateGraphics();
float runningResolution = g.DpiX;
scaleFactor = runningResolution / designResolution;
g.Dispose();

您 在创建动态控件的代码中硬编码坐标,以使用计算出的scaleFactor调整值,例如:

const int controlY = 8;
int yPosition = (int)(controlY * 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:

const float designResolution = 96.0f; 
float scaleFactor;

System.Drawing.Graphics g = f.CreateGraphics();
float runningResolution = g.DpiX;
scaleFactor = runningResolution / designResolution;
g.Dispose();

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:

const int controlY = 8;
int yPosition = (int)(controlY * scaleFactor);
牛↙奶布丁 2024-10-03 20:56:22

我找到了解决这个问题的方法。

我得到的比例因子类似于 simons19 然后,当向表单添加任何动态创建的控件时,我调用方法 control.Scale(scale-factor)。这解决了我的问题。 Scale 方法会缩放控件的位置和大小,因此,我在调用缩放属性之前设置动态创建的控件的位置属性和大小属性。

例子:

Label lblTest = new Label();
lblTest.Text = "A Test Label";
lblTest.Location = new Point(10, 5);  //Designed in relation to a 96 dpi screen
lblTest.Size = new Size(30, 10);      //Size Designed in relation to 96 DPI screen
parentControl.Controls.Add(lblTest);
//Scale Factor is calculated as mentioned by simons19
lblTest.Scale(scaleFactor);           //Scale the control to the screen DPI.

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:

Label lblTest = new Label();
lblTest.Text = "A Test Label";
lblTest.Location = new Point(10, 5);  //Designed in relation to a 96 dpi screen
lblTest.Size = new Size(30, 10);      //Size Designed in relation to 96 DPI screen
parentControl.Controls.Add(lblTest);
//Scale Factor is calculated as mentioned by simons19
lblTest.Scale(scaleFactor);           //Scale the control to the screen DPI.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文