Different window size between framework 2.0 and 3.0

M

Massimo

I have an application where the main window's size is defined at runtime,
based on an image which is displayed inside it.

The application contains a (subclass of) PictureBox which displays the
image; the size of the PictureBox is set to the image's size; the PictureBox
is then placed inside the main form, at a (manually calculated) position
which places it exactly under the app's menu bar and toolbar. The form's
size is then set to a (manually calculated again) size which allows the
PictureBox to fit exactly inside it.

Here's a (shortened) example:

class MainForm: Form
{
public MainForm()
{
InitializeComponent();

Image i = Resources.MyImage; // This uses resource file
Resources.resx
PictureBox pb = new PictureBox;
pb.Size = Image.Size();
pb.Location = new Point(0,44); // 44 is the heigth of the two bars
this.Size = new Size(pb.Width + 6,pb.Height + 76); // This accounts
for borders, etc.
this.Controls.Add(pb);
}
}

The problem: this code works ok when using framework 3.0, but truncates the
image when using version 2.0; when running on framework 2.0, the form's size
is set to values lower than needed, for both height and width, causing part
of the image to not be displayed. The problem isn't related to the size of
the top border and bars, as they're exactly the same (I've compared two
screenshots); it's the form's size that is actually smaller.

I don't know which class originates the problem, as I don't have a machine
with the 2.0 framework available now, but I suspect it can be Image,
PictureBox or Form; it could also be caused by a problem in how the 2.0
framework handles executables wiht included resource files that have been
compiled on version 3.0. What I know is (correct me if I'm wrong) that there
should not be any difference in Windows Forms classes between version 2.0
and 3.0, as version 3.0 only adds some libraries to the 2.0 framework,
without actually changing it.

Can someone please point me in the right direction here?


Thanks


Massimo
 
M

Massimo

The problem: this code works ok when using framework 3.0, but truncates
the image when using version 2.0; when running on framework 2.0, the
form's size is set to values lower than needed, for both height and width,
causing part of the image to not be displayed. The problem isn't related
to the size of the top border and bars, as they're exactly the same (I've
compared two screenshots); it's the form's size that is actually smaller.

It seems this behaviour is actually not related to the framework version:
I've tested the application on a test machine with .NET 2.0 and it works
perfectly.

But I still don't understand why on my customer's machine it displays a
smaller window... making he think the program is buggy, of course :-(


Massimo
 
R

RobinS

Check his DPI settings. If he has a high-resolution monitor, and has the
font settings set to show big fonts, the screen will paint differently than
on another screen.

Robin S.
-------------------------
 

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