views:

51

answers:

2

Hi,

I'm using Visual C# Express 2010 both on my Win7 and XP.

I have a Windows Form Application project, and there is SevenXPForm (inherits Form).

I created it in Visual C# Express 2010 on Win7, and in the Properties panel, I set

.MinimumSize = 300, 300
.Size = 300, 300

And a TabControl is in the middle of the Form:

alt text

However, when I save the project/solution, and open in in Visual C# Express 2010 on WinXP, the size changed to:

.MinimumSize = 300, 279
.Size = 300, 279

And the TabControl is NOT it the middle of the Form any more:

alt text

When I open it on Win7 again, it comes back.

This is haunting me, cuz my application is expected to be working both on XP and Seven, (and Vista).

Do I have to set something to let it behave exactly same both on Win7 and WinXP?

Peter

A: 

After Googling a lot, I still cannot find a solution. But I do have a wordaround to partially solve my problem:

private void SevenXPForm_Load(object sender, EventArgs e)
{
    tabControl1.Width = this.ClientSize.Width - tabControl1.Left * 2;
    tabControl1.Height = this.ClientSize.Height - tabControl1.Top * 2;
}

This is just a workaround, I think there should be a better way to do.

(What if there are a lot of controls on the form? Of course, we can put a panel as the sole child control of the form, and then add all other controls into this panel, which works, but it's too tedious)

Peter Lee
A: 

The problem you are seeing is that the borders around the form differ between Windows XP and Windows 7. This causes the window sizes to differ. How .NET tries to solve this is by instead of saving the size of the window as you see it in the property dialog, it actually saves the ClientSize, which is the inner size of the window. What you see in the property dialog is the size converted to include the outer borders. This means that when you open the project on Windows XP, which has smaller borders, .NET tries to adjust.

It looks like the problem you are seeing is an issue in the conversion. It does seem to take into account the smaller vertical size, but the smaller horizontal size is not taken into account.

Concerning your work around. A different approach to your specific problem/solution would be not to automatically resize the tab control, but to let .NET do this for you. If you set the Padding of the form to e.g. 10, 10, 10, 10 and set Dock of the tab control to Fill, you will get the same effect.

I don't see a general solution here though, because if this is an issue in the conversion that .NET itself does, this becomes very difficult.

Pieter
Hi Pieter, thanks for your reply. I does work, but if there are several controls on the form, I think we need to group them in a Panel. My friend suggested me to make the Form.Size a little bigger than the Form.MinimumSize, and it works with the side effect. Anyway, I will mark yours as the right answer.
Peter Lee
You're welcome.
Pieter