Rendering issue: AutoScrollMinSize and AutoScale

N

Nick

Hi,

I'm running into a scaling issue.
I'm having a simple form. I have some control in that form (2 group boxes,
one dock to the left , the other set to fill, with some misc. controls in
them).
I set the AutoScroll = true on the form and set the AutoScrollMinSize to 700
(which is good at design time).
On XP system, the default font is set to Microsoft Sans Serif, 8.25 point),
everything looks good.
Now if i run this on a different os (say a chinese os, the font used is
different and i'm getting a font of size 9 pt).
Then it looks like the AutoScale is not doing its job properly as it does
not change that 700 value.

Ami i missing something? Should i avoid using the AutoScrolMinSize?
Any way to set that value properly at runtime?

I appreciate any comments on that one

Thanks for your help
 
P

Peter Duniho

[...]
Then it looks like the AutoScale is not doing its job properly as it does
not change that 700 value.

Ami i missing something? Should i avoid using the AutoScrolMinSize?
Any way to set that value properly at runtime?

I'm not aware of any reason to think that the auto-scaling would affect
your scrollbar ranges. While you happen to be using the scrollbar values
here to represent values tied to the dimensions of the form, there's no
requirement that one do that and so always auto-scaling the scroll bar
values according to the form size would be wrong.

Now, that said...

The current approved mechanism for auto-scaling is to use the
AutoScaleMode and AutoScaleDimensions properties. Along with these is an
AutoScaleFactor that you can use to determine the current scaling, and
with that you can apply a correction yourself to the scrollbar range.

If you really insist on using the deprecated AutoScale property, you can
retrieve the base size through AutoScaleBaseSize and then call the
GetAutoScaleSize(). You can then calculate a ratio yourself from that,
and which you can apply to your scrollbar ranges.

Pete
 
N

Nick

Hi Peter,

Thanks a lot for your reply.
I'm not using the deprecated AutoScale mecanism, but the result is the same.
What i would like to do is to get that ScaleFactor that has been used to
re-scale my AutoScrollMinSize value, but i'm not sure how to get that
information.
It looks like the scaling process happen before the constructor of the Form.
This means that in the constructor, the value of the AutoScaleFactor is 1 for
both width and height. Once the scale process is done, the AutoScaleFacor is
resseted to avoid further rescale in case the Scale method is called at
runtime. Value of properties CurrentAutoScaleDimension and AutoScaleDimension
are identical (because the scale process is done)

Would you know how i can get the scaling factor used by AutoScale ?

Does that make sense that the AutoScrollMinSize is not rescaled or is this a
..NET bug?

Let me know what you think

Thanks and have a great day

--
Nick


Peter Duniho said:
[...]
Then it looks like the AutoScale is not doing its job properly as it does
not change that 700 value.

Ami i missing something? Should i avoid using the AutoScrolMinSize?
Any way to set that value properly at runtime?

I'm not aware of any reason to think that the auto-scaling would affect
your scrollbar ranges. While you happen to be using the scrollbar values
here to represent values tied to the dimensions of the form, there's no
requirement that one do that and so always auto-scaling the scroll bar
values according to the form size would be wrong.

Now, that said...

The current approved mechanism for auto-scaling is to use the
AutoScaleMode and AutoScaleDimensions properties. Along with these is an
AutoScaleFactor that you can use to determine the current scaling, and
with that you can apply a correction yourself to the scrollbar range.

If you really insist on using the deprecated AutoScale property, you can
retrieve the base size through AutoScaleBaseSize and then call the
GetAutoScaleSize(). You can then calculate a ratio yourself from that,
and which you can apply to your scrollbar ranges.

Pete
 
P

Peter Duniho

[...]
It looks like the scaling process happen before the constructor of the
Form.
This means that in the constructor, the value of the AutoScaleFactor is
1 for
both width and height. Once the scale process is done, the
AutoScaleFacor is
resseted to avoid further rescale in case the Scale method is called at
runtime. Value of properties CurrentAutoScaleDimension and
AutoScaleDimension
are identical (because the scale process is done)

I don't really understand this part. If AutoScaleDimension were left
unchanged, it wouldn't matter how many times the scaling was done. It
would always reference the original dimensions and whatever other metric
is involved (font size or DPI) and come up with the same auto-scale
numbers each time.

While I can't rule out that this value _is_ getting reset, I don't see why
it would. It should be left unchanged, with the other scaling numbers
getting updated as needed.

Usually when that happens (me not understanding why something happens),
it's because I don't fully understand the API. So my next step would be
to look more closely at the documentation as well as the
designer-generated code to see if I can figure out for sure what's being
set up on my behalf.

I'd recommend you do those things; I don't have enough personal knowledge
to answer those questions myself.
Would you know how i can get the scaling factor used by AutoScale ?

Does that make sense that the AutoScrollMinSize is not rescaled or is
this a
.NET bug?

I don't know. I haven't actually tried the auto-scaling stuff myself. It
seems to me that the AutoScaleFactor should give you relevant
information. If it's not, there are two possibilities: you're not using
it right, or there's a bug.

Use of it seems like it ought to be straightforward, but I've run into
situations in .NET that require non-intuitive steps for things to work.
Maybe this is one of them. I can't rule out a bug, but almost always it
just turns out to be user error. Unfortunately, I don't have the
first-hand experience I'd need to tell you what that "user error" might be.

Pete
 
N

Nick

Hi Peter,

Thanks for your post. Here is what Microsoft says on the subject:

Windows Forms now uses the following logic to automatically scale
forms
and their contents:
1. At design time, each ContainerControl records the scaling mode
and it
current resolution in the AutoScaleMode and AutoScaleDimensions,
respectively.

2. At run time, the actual resolution is stored in the
CurrentAutoScaleDimensions property. The AutoScaleFactor property
dynamically calculates the ratio between the run-time and
design-time
scaling resolution.

3. When the form loads, if the values of CurrentAutoScaleDimensions
and
AutoScaleDimensions are different, then the PerformAutoScale
method is
called to scale the control and its children. This method suspends
layout and
calls the Scale method to perform the actual scaling. Afterwards,
the value
of AutoScaleDimensions is updated to avoid progressive scaling.

I will try to find a way to get the scaling factor applied. Looks like it is
not available though. Then i can use it to re-scale my AutoScrollMinSize
value.

Thanks again for your help

Nick

--
Nick


Peter Duniho said:
[...]
It looks like the scaling process happen before the constructor of the
Form.
This means that in the constructor, the value of the AutoScaleFactor is
1 for
both width and height. Once the scale process is done, the
AutoScaleFacor is
resseted to avoid further rescale in case the Scale method is called at
runtime. Value of properties CurrentAutoScaleDimension and
AutoScaleDimension
are identical (because the scale process is done)

I don't really understand this part. If AutoScaleDimension were left
unchanged, it wouldn't matter how many times the scaling was done. It
would always reference the original dimensions and whatever other metric
is involved (font size or DPI) and come up with the same auto-scale
numbers each time.

While I can't rule out that this value _is_ getting reset, I don't see why
it would. It should be left unchanged, with the other scaling numbers
getting updated as needed.

Usually when that happens (me not understanding why something happens),
it's because I don't fully understand the API. So my next step would be
to look more closely at the documentation as well as the
designer-generated code to see if I can figure out for sure what's being
set up on my behalf.

I'd recommend you do those things; I don't have enough personal knowledge
to answer those questions myself.
Would you know how i can get the scaling factor used by AutoScale ?

Does that make sense that the AutoScrollMinSize is not rescaled or is
this a
.NET bug?

I don't know. I haven't actually tried the auto-scaling stuff myself. It
seems to me that the AutoScaleFactor should give you relevant
information. If it's not, there are two possibilities: you're not using
it right, or there's a bug.

Use of it seems like it ought to be straightforward, but I've run into
situations in .NET that require non-intuitive steps for things to work.
Maybe this is one of them. I can't rule out a bug, but almost always it
just turns out to be user error. Unfortunately, I don't have the
first-hand experience I'd need to tell you what that "user error" might be.

Pete
 

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