我有一个在 Compact Framework 上运行的 .NET 2.0 应用程序。它有一堆不同的形式,最初都是为了在具有特定屏幕分辨率的特定设备上运行而设计的。我现在希望让这个应用程序在具有非常不同的屏幕分辨率的其他一些设备上运行(有些设备具有完全相反的宽高比,其中屏幕现在比宽高)。我的问题是如何更改我的表单以使其在其他屏幕上看起来不错?
这与在完整框架上设计表单有点不同,因为屏幕太小,我必须设计这些表单以占据全屏。我考虑过为每种类型的屏幕方向创建单独的表单(例如 MyForm_Wide.cs、MyForm_Tall.cs 等)。我希望能够重用非设计者生成的代码,其中包含大量与 UI 控件相关的业务逻辑。也许我可以以某种方式使用部分类来实现这一点(例如,MyForm.cs 以某种方式编译成 MyForm_Wide.Designer.cs 等)。我真的很想避免为每个屏幕方向专门编译的版本。我考虑过的另一种方法是尝试根据确定的屏幕尺寸在运行时重新排列一些控件。
你们觉得怎么样?
I have a .NET 2.0 application that runs on Compact Framework. It has a bunch of different forms that were all originally designed to run on a specific device with a specific screen resolution. I'm now looking to get this application to run on some other devices that have very different screen resolutions (some have completely opposite aspect ratios where the screen is now taller than it is wide). My question is how can I change my forms to look good on these other screens?
This is a bit different from designing forms on the full framework since I have to design these forms to take up the full screen since the screens are so small. I've thought about creating separate forms for each type of screen orientation (e.g. MyForm_Wide.cs, MyForm_Tall.cs, etc). I'd like to be able to reuse the non-designer generated code that contains a lot of business logic that is tied to the UI controls. Maybe I could somehow use partial classes to make this happen (e.g. MyForm.cs somehow gets compiled into MyForm_Wide.Designer.cs, etc). I'd really like to avoid specifically compiled versions for each screen orientation. Another approach I've thought about is trying to rearrange some controls at runtime based on the determined screen size.
What do you guys think?
发布评论
评论(5)
由于 C# 设计者非常“面向像素”,因此没有简单的方法来转换表单。
我不知道你想为此付出多少努力,但如果你有很多时间并且想要一个真正灵活的解决方案,我建议你应该使用某种支持流布局、边框布局等的布局管理器。
当然最初的 C# 设计者不会对设计这些灵活的布局管理表单有太大帮助。
但使用布局管理器可能会减慢表单的初始显示速度。如果您想要真正高速的表单显示,则必须在显示表单之前计算表单上所有控件的所有位置。重新排列控件并显示您的表单 - 然而,这需要大量编码,并且对于 gui 更改来说不是很灵活。
Since the c# designers are very 'pixel-orientated' there is no easy way to convert your forms.
I don't know how much effort you want to put into this, but if you have a lot of time and want a really flexible solution I suggest you should use some kind of layout manager that supports flow layouts, border layouts etc.
Of course the original c# designers won't be much help designing these flexible layout-managed forms.
But using a layout manager might slow down the initial display of your form. If you want really high speed form display you will have to calculate all positions of all controls on your form before you show the form. Rearrange the controls and display your form - this is however a lot of coding and not very flexible regarding gui changes.
您可能应该将主窗体的“AutoScaleMode”属性设置为“DPI”。
然后,就是使用锚点并停靠在表单上的特定控件上。如果您这样做,紧凑的框架将使事情保持在您想要的位置。
此外,还可以更改表单的“Form Factor”属性,以查看表单在不同尺寸和形状的移动设备上的外观。
You should probably set your main forms 'AutoScaleMode' property to 'DPI'.
Then, its a matter of using anchors and docking on your particular controls on the forms. If you do it this way, the compact framework will keep things where you thought they'd be.
Also, can change the 'Form Factor' property of the form to see how your form would look on mobile devices of different sizes and shapes.
我想我已经弄清楚我想做什么了。由于某种原因,即使在我的高分辨率设备上,根据 WinForms API,DPI 仍然显示为 96,因此自动缩放没有执行任何操作。相反,如果我手动调用
Scale
在我的控件上,我可以让它们按照我想要的方式进行扩展。现在,这并不能完全解决我不想进行任何缩放的情况下的问题,但如果屏幕的宽高比与我最初设计的相反,我确实想重新组织我的控件。对于这种情况,我想我将考虑使用不同的布局面板(例如FlowLayoutPanel
和TableLayoutPanel
)希望能够适当地组织控件。希望这对未来的 Google 员工有所帮助...
I think I've figured out what I want to do. For some reason even on my high res devices the DPI still shows up as 96 according to the WinForms API so the auto scaling isn't doing anything. Instead, if I manually call
Scale
on my controls I get them to scale out exactly how I want. Now, this doesn't completely solve my problem in scenarios where I don't want to do any scaling but I do want to reorganize my controls if the screen is in the opposite aspect ratio than what I originally designed for. For that case, I think I'm going to look at using different layout panels (e.g.FlowLayoutPanel
andTableLayoutPanel
) to hopefully organize the controls appropriately.Hopefully this will help any future Googler...
在外形尺寸之间切换时,标签上的“自动大小”属性也会变得混乱 - 顺便说一句 - 所以我将其设置为 false。
The 'Auto Size' property on labels messes up when switching between form factors too - btw - so I keep it set to false.
我们使用 Clarius 的 方向感知控制 框架。它不仅解决了外形尺寸的问题,还解决了支持它的设备上方向变化(屏幕旋转)的问题。
We use the Orientation Aware Control framework by Clarius. It solves the problem of not only form factor, but also on devices that support it, change of orientation (screen rotation).