Large Fonts not scaling correctly on tab control.

G

Guest

I have a problem which I have been able to reproduce in a very simple project.

I have a form with a single tabcontrol control with two tab pages. The
tabcontrol's Anchor property is set to Top, Left, Bottom, Right (all 4
directions). On each tabpage, I have a DataGrid. Each DataGrid's Anchor
property is also set to Top, Left, Bottom, Right. I developed this simple
application with my System's DPI setting set to Normal Size (96) and
everything worked perfectly.

The problem came, however, when I changed my DPI setting to Large (120).
The datagrid on the first tabpage (index 0) did not have the correct size
(too large). On the second tabpage (and any others that were present in
subsequent tests), everything was sized correctly.

The same problem happens in reverse (developing in Large and moving to
Normal).

My workaround was to create an empty tabpage at the beginning of the set and
remove it from the tabcontrol's TabPages collection during the form's load
event handler. I could have also not used anchor and changed the control's
width during the form's resize event.

Any non-hack solution or explanation would be appreciated.
 
G

Guest

Thank you for posting this workaround. I am also seeing this problem with a
tabcontrol and a simple textbox which is anchored left and right. Have you
ever found an explanation or more permanent solution?
 
G

Guest

We had the same problem in our Forms, too.

Circumstances, under which this situation occurs, are:
- There is a Control (WindowsForms or UserControl or whatever), which is
located in first TabPage of a TabControl
- The Control is either anchored: Left, Right (which means it will resize
every time the parent container resizes) or is Docked: Fill (which also means
resizing)
- TabControl is visible

Problem: the control has incorrect size compared to the TabControl where it
is located.

Cause: When the form has property AutoScale=True (default), when it is
created, a protected method of this form named ScaleCore is called, which
resizes the form and all child controls (this is done behind the scene, you
cannot see it in code).
Then every child controls resizes its own child controls, too.
In our case: The Form resizes TabControl, which resizes TabPages, which then
resize their Controls.
Until now all is correct. Unfortunately it seams there is a bug in .NET FW:
Controls, which are on first (on visible) TabPage and are either anchored:LR
or docked:Fill, are scaled twice: once directly by the Form itself and then
by parent control (TabPage).

Result: when the form is opened on computer with different System DPI than
on which the application was developed (ex. 120 dpi against 96 dpi), then the
control will be overscaled.

Solutions:
1. To have empty TabPage, which will be removed on Form.Load event, as done
by Wyatt;
2. To make the TabControl invisible at design time (TabControl.Visible=false)
and to make it visible on Form.Load event (TabControl.Visible=true). This is
the solution we use, because it has minimal impact on the code.
3. To wait until Microsoft fixes the problem (maybe it will be fixed in .NET
FW 2.0)

Best regards,
Georgi
 

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