Visual C# 2010 Express:Win7 和 WinXP 上的窗体相同但大小不同

发布于 2024-09-28 21:17:56 字数 700 浏览 5 评论 0原文

我在 Win7 和 XP 上都使用 Visual C# Express 2010。

我有一个Windows窗体应用程序项目,并且有SevenXPForm(继承Form)。

我在 Win7 上的 Visual C# Express 2010 中创建了它,并在“属性”面板中设置了

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

TabControl 位于窗体的中间:

alt text

但是,当我保存项目/解决方案并在 WinXP 上的 Visual C# Express 2010 中打开时,大小更改为:

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

并且 TabControl 不再是窗体的中间:

alt text

当我再次在 Win7 上打开它时,它又回来了。

这让我很困扰,因为我的应用程序预计可以在 XP 和 7(以及 Vista)上运行。

我是否必须设置一些东西才能让它在 Win7 和 WinXP 上表现完全相同?

彼得

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

东北女汉子 2024-10-05 21:17:56

您看到的问题是 Windows XP 和 Windows 7 之间的窗体边框不同。这会导致窗口大小不同。 .NET 尝试解决此问题的方法是,它实际上保存的是 ClientSize,即窗口的内部大小,而不是像您在属性对话框中看到的那样保存窗口的大小。您在属性对话框中看到的是转换为包含外边框的尺寸。这意味着当您在边框较小的 Windows XP 上打开项目时,.NET 会尝试进行调整。

看来您遇到的问题是转换中的问题。它似乎确实考虑了较小的垂直尺寸,但没有考虑较小的水平尺寸。

关于你的工作。针对您的特定问题/解决方案的不同方法是不自动调整选项卡控件的大小,而是让 .NET 为您完成此操作。如果将表单的 Padding 设置为例如 10, 10, 10, 10 并将选项卡控件的 Dock 设置为 Fill,你会得到同样的效果。

不过,我在这里没有看到通用的解决方案,因为如果这是 .NET 本身进行的转换中的问题,那么这将变得非常困难。

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.

凑诗 2024-10-05 21:17:56

经过多次谷歌搜索后,我仍然找不到解决方案。但我确实有一个解决办法来部分解决我的问题:

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

这只是一个解决方法,我认为应该有更好的方法。

(如果窗体上有很多控件怎么办?当然,我们可以放一个面板作为窗体的唯一子控件,然后将所有其他控件都添加到这个面板中,这样也可以,但是太繁琐了)

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)

把回忆走一遍 2024-10-05 21:17:56

更可靠的解决方法是将整个表单的内容放入面板中,并将对接设置为填充,然后像在该面板中那样排列所有内容。在这个问题得到解决之前(假设它曾经得到解决),我建议您对创建的每个表单都理所当然地这样做。

A more robust workaround is to put the contents of the entire form in a panel with the docking set to fill, and then line up everything as you otherwise would in that panel. Until this issue is fixed -- assuming that it ever is -- I'd recommend doing this as a matter of course for every form you create.

澉约 2024-10-05 21:17:56

请查看此链接:

http://msdn.microsoft.com/en -us/library/ms229605.aspx

--

快速查看

自动缩放使在具有特定显示分辨率或系统字体的一台计算机上设计的表单及其控件能够正确显示在具有不同显示分辨率或系统字体的另一台机器。它确保表单及其控件将智能地调整大小,以与用户和其他开发人员计算机上的本机窗口和其他应用程序保持一致。 .NET Framework 对自动缩放和视觉样式的支持使 .NET Framework 应用程序与每个用户计算机上的本机 Windows 应用程序相比能够保持一致的外观和感觉。

Please take a look on this link:

http://msdn.microsoft.com/en-us/library/ms229605.aspx

--

Quick View

Automatic scaling enables a form and its controls, designed on one machine with a certain display resolution or system font, to be displayed appropriately on another machine with a different display resolution or system font. It assures that the form and its controls will intelligently resize to be consistent with native windows and other applications on both the users' and other developers' machines. The support of the .NET Framework for automatic scaling and visual styles enables .NET Framework applications to maintain a consistent look and feel when compared to native Windows applications on each user's machine.

新人笑 2024-10-05 21:17:56

这是一个老问题,但它在谷歌中,所以我有一个答案,可能对其他人有用,所以我会分享它(对不起我的英语)。

1)绘制面板1
2) Form1_Load 部分中的 panel1.Dock = DockStyle.Fill
3)现在您可以使用panel1的宽度和高度来获取Form1的真实宽度和高度,无论您使用哪种操作系统(Win XP或7),无论表单边框样式。

It's old question, but it is in Google, so I have an answer, which may be useful for others, so I will share it (sorry for my English).

1) draw a panel1
2) panel1.Dock = DockStyle.Fill in Form1_Load section;
3) now you can use panel1 width and height to get real width and height of Form1, no matter which OS (Win XP or 7) you are using, no matter form border style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文