VGA and dynamic placement of controls

S

scottelloco

Hi,

I'm developing a CF application to run on VGA and QVGA devices with
both 240x320 and 240x240 screens. I have everything working fine on
both screen sizes in QVGA mode, but VGA is giving me some problems.
I'm trying to write as little code as possible to accommodate for all
of these variables. I'm using VS 2005, C#, CF 2.0 and the VS 2005 VGA
emulator for testing (unfortunately I don't have a real VGA device to
determine if this is an issue with the emulator.)

I have a form with one textbox and two buttons (code below.) I
calculate the size of the of the textbox based on the right and bottom
bounds of the WorkignArea of the screen. In VGA mode when AutoScale
mode is set to dpi and AutoScaleDimensions is (96F, 96F) the textbox
huge and flows way off of the screen. The buttons size are static and
are the correct relative size in this scenario.

When I during off AutoScale then my textbox fits on the screen, since
the sizing is dynamic based on the WorkingArea parameters, but the
buttons are a quarter of the size they should be (as I would expect)
since their size is static.

Code:

this.AutoScaleDimensions = new System.Drawing.SizeF(96F,
96F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Dpi;

int gScreenTop =
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top;
int gScreenBottom =
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom;
int gScreenLeft =
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left;
int gScreenRight =
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;

//
// btnSync
//
this.btnSync.Size = new System.Drawing.Size(93, 21);
this.btnSync.Location = new
System.Drawing.Point((gScreenRight / 2) + 13, gScreenBottom - 80);

//
// btnCancel
//
this.btnCancel.Size = new System.Drawing.Size(93, 21);
this.btnCancel.Location = new
System.Drawing.Point(((gScreenRight / 2) - (btnCancel.Size.Width)) +
11, gScreenBottom - 80);

//
// txtStatus
//
frmSync.txtStatus.Location = new System.Drawing.Point(10,
10);
frmSync.txtStatus.Size = new
System.Drawing.Size(gScreenRight - 20, gScreenBottom - 100);

When on a VGA device, gScreenBottom = 640 and gScreenRight = 480. I
center the buttons by dividing the ScreenWidth by 2 and then taking
into account the size of the buttons, I then add a little buffer space
between the buttons.

In QVGA this technique works fine, but in VGA it seems to think that
the right bound (640) is way off to the right of the actual visible
screen and that the bottom bound (480) is way off the bottom of the
visible screen, so my buttons end up somewhere way down in never-never
land.

The same thing for the textbox. It overflows way past the end of the
screen when AutoScale is on. However when Autoscale is off the textbox
fits correctly on the screen (except as I mentioned and as I would
expect the button are a 1/4 of the size they should be, since their
size is static.)

Another thing that seems weird is that when AutoScale is true, the
WorkingArea.Top = 52 (the height of the top menu bar), but when
AutoScale is false WorkingArea.Top = 26. Should it always be 26 since
AutoScale should adjust for VGA mode?

Any assistance or links to information would be greatly appreciated.
I've searched around a read a good deal about developing for VGA and
QVGA devices, but this has me stumped.

Thanks, -Scott
 
G

Guest

The behavior you describe actually makes perfect sense to me. VGA is
640x480. When you try to autosize, it pixel-doubles a 320x240 screen to fit
it. With auto-scale, a 540x4802 and a 320x240 app should need zero
modifications (excepti it might look ugly due to the pixel doubling).

You might look at anchoring and docking instead - it gives a lot better
results for resolution changes.
 
S

scottelloco

The behavior you describe actually makes perfect sense to me. VGA is
640x480. When you try to autosize, it pixel-doubles a 320x240 screen to fit
it. With auto-scale, a 540x4802 and a 320x240 app should need zero
modifications (excepti it might look ugly due to the pixel doubling).

You might look at anchoring and docking instead - it gives a lot better
results for resolution changes.

Thanks for your reply ctacke. What you're saying makes sense, but I
think what is confusing em the most is why
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right would
point to an area that is way outisde of the visible screen. Shouldn't
WorkingArea.Right be the x coordinate of the furthest point to the
right ont he visible screen?

Thanks, -Scott
 
G

Guest

Thanks for your reply ctacke. What you're saying makes sense, but I
think what is confusing em the most is why
System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right would
point to an area that is way outisde of the visible screen. Shouldn't
WorkingArea.Right be the x coordinate of the furthest point to the
right ont he visible screen?

Yes, and it is. On a VGA device in portrait mode, that's a value of 480.
However if you have a Form set to autoscale and you are on a VGA device,
it's going to pixel-double. That means 480 is going to become 960. Remember
the *Form* is auto-scale, not the Screen, so querying Screen properties is
not affected by any scaling.
 
S

scottelloco

Yes, and it is. On a VGA device in portrait mode, that's a value of 480.
However if you have a Form set to autoscale and you are on a VGA device,
it's going to pixel-double. That means 480 is going to become 960. Remember
the *Form* is auto-scale, not the Screen, so querying Screen properties is
not affected by any scaling.

Got it. Thanks very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top