Search code examples
c#compact-frameworkautoscalemode

Force .NetCF 1.0 Scaling model to .NetCF 2.0 application


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.


Solution

  • 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.