Pictureboxes moving on their own volition when form is displayed

R

RobinS

I have a user control that has this structure from top to bottom:

Label1
Label2
PictureBox1
Label3
PictureBoxes2 through 11

All of the controls are anchored Top,Left. Pictureboxes 2 through 11 are
right next to each other in the designer, with 1 pixel of space between
them.

This user control is added to a form that has this structure:

Form
TopLevelSplitContainer
TopLevelSplitContainer.Panel1
other stuff
TopLevelSplitContainer.Panel2
justAPanel
myUserControl
aDGV

Depending on something happening in the background, it displays the
UserControl or the DGV.

The problem is when I the UserControl is displayed in my form, it spaces out
pictureboxes 2 through 11 and ends up chopping off the right side of the
last picturebox.

I am adding the UserControl programmatically, but even if I just drop it on
the justAPanel in the designer, it does the same thing.

If I don't anchor the controls on MyUserControl at all, they don't spread
correctly vertically, and they are actually wider horizontally than they
would be if I anchored them.

When added programmatically to the form, the usercontrol is set to dock Left
and Top. If I don't dock it, it seems to center it, which chops off both
sides of the usercontrol.

Any ideas why my controls are being rendered differently in run mode than
they are in design mode?

My containing form is a user control, too, by the way, which does sit in an
actual Form that has a minimum size and a default size that this panel
should fit into if it weren't mucking up my picturebox locations.

The reason I have 10 picture boxes is because each one has its own click
event. Just thought I'd throw that in there before someone says "Why don't
you just combine the picture boxes into one?".

Sorry for the cross-posting; I'm desperate.

Thanks in advance.
RobinS.
GoldMail.com
 
R

RobinS

RobinS said:
I have a user control that has this structure from top to bottom:

Label1
Label2
PictureBox1
Label3
PictureBoxes2 through 11

All of the controls are anchored Top,Left. Pictureboxes 2 through 11 are
right next to each other in the designer, with 1 pixel of space between
them.

This user control is added to a form that has this structure:

Form
TopLevelSplitContainer
TopLevelSplitContainer.Panel1
other stuff
TopLevelSplitContainer.Panel2
justAPanel
myUserControl
aDGV

Depending on something happening in the background, it displays the
UserControl or the DGV.

The problem is when I the UserControl is displayed in my form, it spaces
out pictureboxes 2 through 11 and ends up chopping off the right side of
the last picturebox.

I am adding the UserControl programmatically, but even if I just drop it
on the justAPanel in the designer, it does the same thing.

If I don't anchor the controls on MyUserControl at all, they don't spread
correctly vertically, and they are actually wider horizontally than they
would be if I anchored them.

When added programmatically to the form, the usercontrol is set to dock
Left and Top. If I don't dock it, it seems to center it, which chops off
both sides of the usercontrol.

Any ideas why my controls are being rendered differently in run mode than
they are in design mode?

My containing form is a user control, too, by the way, which does sit in
an actual Form that has a minimum size and a default size that this panel
should fit into if it weren't mucking up my picturebox locations.

The reason I have 10 picture boxes is because each one has its own click
event. Just thought I'd throw that in there before someone says "Why don't
you just combine the picture boxes into one?".

Sorry for the cross-posting; I'm desperate.

Thanks in advance.
RobinS.
GoldMail.com

So here is what I figured out through trial and error.

The panel on which my controls sit has an AutoScaleMode of "Font".
Apparently when it renders, it scales up and repositions everything on the
screen, which includes spacing the graphics out. When I set this to "None",
the graphics stay in place.

This is a little frustrating, because I have been tasked with changing all
of the forms (and underlying user controls) to display correctly on a
computer running "big fonts" (dpi=120). Right now, our app only looks right
on 96-dpi setting.

Before you post back and say "set autoscalemode to dpi", I'll pass on that I
tried that, and I think the problem I'm having is that the distance on our
splitter controls is hardcoded, as well as the default size of our
application, and apparently I'm going to have to do some math to fix that
problem. We don't want the user to be able to change the splitter position.

Also, from what I've read about AutoScaleMode, if you set it to "Font", it
will scale for both Font and DPI changes. We are not currently really
supporting international users (many have our product, but it's all in
English for the moment), but when we do, I assume I'm going to want the
forms to scale by Font as well as by DPI.

If anybody has any wisdom about the whole AutoScaleMode topic, I'd love to
hear it, as this is looming quite large on my to-do list.

Thanks very much.

RobinS.
GoldMail.com
 
P

Peter Duniho

[...]
If anybody has any wisdom about the whole AutoScaleMode topic, I'd love
to hear it, as this is looming quite large on my to-do list.

It seems to me that if you're using any auto-scale mode, you necessarily
give up the right to expect things to be presented exactly as you had
originally designed them.

It's possible that by setting the AutoSize and AutoSizeMode properties on
appropriate controls (such as your UserControls) you get some different
behavior that is more to your liking, or that you can implement your own
auto-scale logic and set the form's scaling to "none". But at the end of
the day, you're asking .NET to resize things according to some external
information, and it shouldn't be too surprising that your carefully
laid-out arrangement gets disturbed.

It may be that the most appropriate solution is simply to not design
something that is so sensitive to variations in size and position. Leave
things some room to be scaled and adjusted without creating problems that
are causing you to dislike the current behavior now.

Pete
 
R

RobinS

Peter Duniho said:
[...]
If anybody has any wisdom about the whole AutoScaleMode topic, I'd love
to hear it, as this is looming quite large on my to-do list.

It seems to me that if you're using any auto-scale mode, you necessarily
give up the right to expect things to be presented exactly as you had
originally designed them.

It's possible that by setting the AutoSize and AutoSizeMode properties on
appropriate controls (such as your UserControls) you get some different
behavior that is more to your liking, or that you can implement your own
auto-scale logic and set the form's scaling to "none". But at the end of
the day, you're asking .NET to resize things according to some external
information, and it shouldn't be too surprising that your carefully
laid-out arrangement gets disturbed.

It may be that the most appropriate solution is simply to not design
something that is so sensitive to variations in size and position. Leave
things some room to be scaled and adjusted without creating problems that
are causing you to dislike the current behavior now.

Pete

I was hoping by setting autoscale mode that it would scale text, not
pictures. That was my expectation. And why would it scale the positioning of
the pictures without scaling the actual pictures as well? It seems
inconsistent to me.

If you are fortunate enough to only support applications where you can put a
bunch of extra space in your panels in case the user has a higher DPI
settings, then that's great. I don't have that luxury.

I figured at this point I would go through each form and user control and
see what works. We have what basically amounts to four panels on the screen
with two across and two down. To make the panels large enough for the text
to be okay when sized up would make the screen ugly for users having dpi set
to 96 dpi. It is clear to me at this point that I am going to have to
programmatically handle the sizing of some of the forms and splitters to
display cleanely without a lot of extra space, and without being truncated.

Thanks anyway.

RobinS.
GoldMail.com
 
P

Peter Duniho

I was hoping by setting autoscale mode that it would scale text, not
pictures. That was my expectation. And why would it scale the
positioning of the pictures without scaling the actual pictures as well?
It seems inconsistent to me.

If it's scaling the picture, it's because you've set the PictureBox
control to stretch the picture. Auto-scaling isn't going to directly
affect how your images render, but it _will_ resize all of the controls
that are affected, and if you've set your PictureBox to both auto-scale
and stretch any contained image, then of course the image within will be
scaled as well as the control itself changes size.

As far as the auto-scaling stuff is concerned, the PictureBox is just like
any other control. It doesn't treat it differently just because it's
containing an image, nor is there any reason to expect that it would know
or care.

I don't find it inconsistent. If anything, it would be inconsistent for
..NET to treat a PictureBox differently, especially given that there are
image display modes for PictureBox that don't stretch the image.

Pete
 
R

RobinS

Peter Duniho said:
If it's scaling the picture, it's because you've set the PictureBox
control to stretch the picture. Auto-scaling isn't going to directly
affect how your images render, but it _will_ resize all of the controls
that are affected, and if you've set your PictureBox to both auto-scale
and stretch any contained image, then of course the image within will be
scaled as well as the control itself changes size.

As far as the auto-scaling stuff is concerned, the PictureBox is just like
any other control. It doesn't treat it differently just because it's
containing an image, nor is there any reason to expect that it would know
or care.

I don't find it inconsistent. If anything, it would be inconsistent for
.NET to treat a PictureBox differently, especially given that there are
image display modes for PictureBox that don't stretch the image.

Pete

Thanks, Pete. I'll buy that; it makes more sense when you put it that way.

RobinS.
GoldMail.com
 

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