在InitializeComponent()期间触发Form.OnResize

发布于 2024-08-20 22:57:33 字数 573 浏览 2 评论 0原文

我在 XP 英语机器和 XP 日语机器上运行相同的 UI 代码。 由于某种原因 - 这两台机器之间的行为不同:

在日本机器上,OnResize 事件在 InitializeComponent 调用期间被触发(我认为是从 ResumeLayout 函数中触发的)。在英文机器上则不然。

我有一个 OnResize 的重写方法,可以更改我定义的私有变量的值。由于组件未完全加载(Ctor 仍在运行),因此这些变量为 null,并且出现异常。

我可以通过检查变量是否为空来修复代码,但我想了解为什么它首先被调用以及为什么它只发生在这台机器上。

在网上搜索期间,我发现了其他人发布的相同问题,但没有解决方案(http://social.msdn.microsoft.com/Forums/en/winforms/thread/95aefae4-45d8-4ac5-a8f2-6e2142dfb631)。

I have the same UI code running on my XP English machine and on XP Japanese machine.
For some reason - the behavior is different between those two machines:

On the Japanese machine the OnResize event is getting triggered during the InitializeComponent call (I think that from ResumeLayout function). On the English machine it doesn't.

I have an override method of OnResize that change values of my private variables that I defined. Since the component was not fully loaded (the Ctor is still running), those variables are null and I get an exception.

I can fix the code by checking if the variable is null or not, but I would like to understand why it is getting called in the first place and why it happens only on this machine.

During my search over the net I found the same problem that someone else has posted, but with no solution (http://social.msdn.microsoft.com/Forums/en/winforms/thread/95aefae4-45d8-4ac5-a8f2-6e2142dfb631).

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

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

发布评论

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

评论(1

阿楠 2024-08-27 22:57:33

正确披露:我正在与 Hila 合作,因此我能够看到代码。
不同行为的原因是由于控件的一个名为 AutoScaleMode 的属性造成的。在控件的基类中,此属性的值为 AutoScaleMode.Font。由于我们所有的研发机器都以相同的设置(英语)运行,因此它们表现正常,并且错误没有发生在那里。更改为日语机器意味着与英语机器上的字体设置不同。这就造成了麻烦。因此,我们将 AutoScaleMode 属性的值更改为 None,解决了该问题。 结论:注意 AutoScaleMode 属性。

Proper disclosure: I am working with Hila so I was able to see the code.
The reason for the different behaviour was due to the a property of the control called AutoScaleMode. In the base class of the control the value of this property was AutoScaleMode.Font. Since all our R&D machines are running with the same settings (English) they behaved properly and the bug didn't happen there. Changing to a Japanese machine meant different font settings from the ones on the English machines. This caused the trouble. So we changed the value of the AutoScaleMode property to None and it solved the issue. Conclusion: beware of the AutoScaleMode property.

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