开发者

Compact Framework: Show Dialog and executing code AFTER the form shows

Working in .开发者_开发知识库NET Compact Framework, C#, .Net 3.5, Visual Studio 2008. Targeting Windows Mobile and CE devices from the same project (it's a CE app, runs on both types of devices).

I have a form that must be displayed using ShowDialog. the form itself is just a blank screen with a "loading..." message on it. AFTER the form displays on the screen, I need to run another chunk of code on the same thread that will pop up another form using ShowDialog, so that the "Loading" screen is the parent of the new screen.

don't tell me that this scenario is wrong or i shouldn't use showdialog. we've been through that as a team and this is the way we are writing the app because it solves a significant number of other problems.

... the problem with this scenario, though, is that there is no Shown even in compact framework, so I can't do my usual trick of putting code in that event to do this.

how do other people solve this need in compact framework? if it helps, i do have the OpenNetCF library... is there something in there that can help?


Okay, I'll resist my very strong urge to tell you that this is wrong and you shouldn't be using ShowDialog. Now that I've not said it, let's look at what's going on.

Your app calls Application.Run at some point. That sets up a message pump that dispatches Windows events to the proper Windows (controls) in the system.

When you call ShowDialog, the system sets up another temporary message pump. This means that Windows events coming into this pump will not get dispatched outside to other controls (this is how you get the modality).

Now you're saying you need to pop yet another dialog on top of that (so creating yet another pump) but you need it to come up after some sort of initialization code in the first Dialog (not the overall parent Form) has been displayed.

Is this all correct? If so, I think there are two routes I'd look at. First, I'd look at overriding OnActivated in the first Dialog. Since you're using ShowDialog I'd think that it would be nearly synonymous with the Shown event.

If that doesn't quite get you what you want, then I'd look at adding a MessageWindow to the first dialog (or using the SDF's NativeWindow to subclass it) and look at all of the Windows messages coming in to provide your own Shown event.


ended up using form activate with a boolean to check and see if i've done the work or not

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜