Compact Framework的最佳实践:构建一个GUI [英] Compact Framework best practices: Building a GUI

查看:237
本文介绍了Compact Framework的最佳实践:构建一个GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保持建立在.NET Framework中,有大约45形成了一个Windows CE的应用程序。有5个'节',这会导致你想要的功能。该应用程序是100%全屏幕,这是重要的,它不能被最小化。

既然有这么多的形式,这是很难跟踪哪些形式的人应该被关闭后显示。对于这一点,我设置的形式owner属性显示它,并显示主人收盘时前。

我也被告知,这是最好的实例一切形式的应用程序加载时,并没有出售他们节省处理时间。我不知道这件事。

我的问题是,什么是去展示,隐藏在那里你想要的任何1形式在前面的形式最好的方式,全屏幕上的所有时间?

解决方案

我不会去实例45表格应用程序启动时的路线。这将极大延长启动时间和可能(如果没有可能)耗尽内存资源,所有提供的功能,您的用户甚至不需要。

在我的WinMo应用中,每个表格被设计数据的相对小的子集来工作,因此启动时间限制在数据库调用和加载数据到窗体的控制。通常情况下,所需要的时间,以实例化这些形式之一,并显示它是从不低于第二或两个以上。

如果您的形式需要的时间比这表明,它可能是有一个与你的数据检索或将数据加载到窗体的控件(例如,您可能有一个自定义GridView控件,充分呈现所有300的方式有问题即使只有12行是一次可见)。如果您的数据是如此之大,它合法需要很长的时间来恢复,很可能是更多的数据,而不是用户几乎可以用反正互动。

我想你提到的5个部分来获得,用户需要去意味着他们可能会(在最大)是向下钻取5个层次的东西。如果你让每个实例化的形式实现这一点,并显示下一个形式使用的ShowDialog ,你将有最多5-6的形式存在,在任何一个时间,那些不应该对于一个.net CF应用程序(我做这一切的时候)有任何问题。这样一来,你就不必做什么特别的跟踪哪些形式应该显示的时候 - 你只需打开在任何地方的一种形式,当窗体关闭你自动返回给调用形式。

有一些z顺序/任务管理器的怪事,你必须处理,但它不是特别复杂。在调用的ShowDialog 子窗体上,你父窗体的文本属性设置为空字符串,然后将其设置回窗体的标题原后的ShowDialog 的回报。这不是绝对必要的,但是,在Windows Mobile(至少到6版)所有打开的.Net形式(与非空白文本属性)显示在正在运行的程序列表,即使他们都来自同一个应用。我一般喜欢我多形式的应用程序似乎只是一个程序,所以我通常设置各种形式的文字应用程序的名称)。

我还尝试了一个实现每一块UI作为用户控件,而不是一种形式,然后创建和堆栈的控制,如果你是创建开放形式的单窗体应用程序。这工作,但它是一个黑客,我不建议这样做。形式有Load事件和用户控件不这样做,这是主要的问题。

I'm maintaining a Windows CE app built with the .NET Framework that has about 45 forms. There are 5 'sections' which lead to the function you want. The application is 100% full screen and it is important that it can't be minimized.

Since there are so many forms, it's difficult to keep track of which form should be displayed after one is closed. For this, I'm setting the form owner property before showing it, and showing the owner when closing it.

I've also been advised that it is best to instantiate all forms when the application loads, and not dispose them to save processing time. I'm not sure about this.

My question is, what is the best way to go about showing, hiding forms where you want any 1 form to be in front, full screen all time?

解决方案

I would not go the route of instantiating 45 forms when the application starts. This would severely lengthen the startup time and possibly (if not probably) exhaust your memory resources, all to provide functionality that your user may not even need.

In my WinMo applications, each form is designed to work with a relatively small subset of data, so the startup time is limited to database calls and loading the data into the form's controls. Typically, the time required to instantiate one of these forms and show it is never more than a second or two.

If your forms are taking longer than this to show, it's possible that there's a problem with your data retrieval or with the way the data is loaded into the form's controls (e.g. you might have a custom gridview control that fully renders all 300 rows even though only 12 are visible at one time). If your data is so large that it legitimately takes a long time to retrieve, chances are that's far more data than a user can practically interact with anyway.

I assume your mention of "5 sections" to get where the user needs to go means that they might (at a maximum) be "drilling down" 5 levels to something. If you implemented this by having each form instantiate and show the next form using ShowDialog, you would have at most 5-6 forms in existence at any one time, which shouldn't be any problem for a .Net CF application (I do this all the time). This way, you don't have to do anything special to keep track of which form should be shown when - you just open a form from wherever, and when the form is closed you're automatically back to the calling form.

There is some z-order/task manager weirdness that you have to deal with, but it's not especially complicated. Before calling ShowDialog on the child form, you set the parent form's Text property to a blank string, and then set it back to the form's original caption after ShowDialog returns. This isn't strictly necessary, but in Windows Mobile (at least up to version 6) all open .Net forms (with a non-blank Text property) show up in the Running Programs list, even if they're all from the same application. I generally like my multi-form applications to appear to be just one program, so I usually set the Text of every form to the name of the application).

I've also experimented with a single-form application that implements every piece of UI as a UserControl instead of a Form, and then creates and stacks the controls as if you were creating and opening forms. This works but it's a hack and I don't recommend it. Forms have a Load event and UserControls don't, which is the main problem.

这篇关于Compact Framework的最佳实践:构建一个GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆