通过少量代码更改有效处理所有控件的方向更改

发布于 2024-08-20 23:51:16 字数 296 浏览 1 评论 0原文

我有一个用 C# 构建的 Windows Mobile 项目。

我有很多现成的表单,上面有各种控件,从列表视图到编辑字段。 当用户更改方向时,某些元素无法正确刷新。例如,列表视图的列是相同的,并且不适应新的屏幕宽度变化(出现滚动条或填充一半屏幕)。

您如何应对这些变化?
我是否需要为每个表单手动调用这些修复,或者我可以创建某种全局方法来修复此问题?如果可能的话,我想采用最简单的方法。

我想避免使用经典方法,将代码添加到我的所有表单中。所以我正在寻找更好的方法,我希望看到更多的想法。

I have a Windows Mobile project built in C#.

I have a lot of ready made forms having various controls on it, from Listviews to Editfields.
When user changes orientation some elements are not refreshing correctly. For example the Listview's columns are same and doesn't accommodate the new screen width change (scrollbars appear or half of the screen is filled).

How do you handle these changes?
Do I need to call for each form these fixes by hand, or I can create some kind of global way to fix this? I would like to go with the simplest method if possible.

I would like to avoid the classic way, to add code to all of my forms. So I am looking for better ways, and I would like to see more ideas.

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

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

发布评论

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

评论(1

怪我入戏太深 2024-08-27 23:51:16

我假设您的大多数控件都使用 DockStyle,这将使您在方向更改时更新 GUI 方面完成 90% 的工作。对于 ListView,您必须添加一些代码。

您可以在 Form.Resize 上添加事件处理程序,并在其中放入代码来调整 ListView 列的大小。您可以通过比较宽度和高度来区分纵向和横向。还有一种方法可以在实际方向变化时添加事件处理程序,但它是互操作的,我不记得代码了。 Form.Resize 对于大多数情况来说应该足够了。

您可以在此处查看示例

I'm assuming that most of your controls are using a DockStyle, and that will get you 90% of the way in terms of updating the GUI on orientation changes. For the ListView, you'll have to add in some code.

You can add an event handler on Form.Resize, and there put in code to resize the ListView columns. You can tell portrait vs landscape by comparing width vs height. There's also a way to add an event handler on an actual orientation change, but it's interop and I don't remember the code offhand. Form.Resize should be sufficient for most cases.

You can check out an example here

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