I need to create a status dialog for a Windows Mobile application (C# 2.0) that needs to be updated, so MessageBox is out. I tried to just create a new Form class, change the size and call ShowDialog, but it always comes up full screen (minus the title bar of course). The only way I could figure out how to display it small is to set FormBorderStyle to None, but then it really does have no border or title bar at all!
我需要为需要更新的Windows Mobile应用程序(C#2.0)创建一个状态对话框,因此MessageBox已经用完。我试图创建一个新的Form类,更改大小并调用ShowDialog,但它总是全屏显示(当然减去标题栏)。我能弄清楚如何显示它的唯一方法是将FormBorderStyle设置为None,但它确实没有边框或标题栏!
I want it to still look like a message box (with title bar and borders) but, I need to actually use a Form so I can update it.
我希望它仍然看起来像一个消息框(带标题栏和边框),但是,我需要实际使用一个表单,以便我可以更新它。
Any ideas of how to do this?
有关如何做到这一点的任何想法?
2 个解决方案
#1
2
The challenge here is the WinMo shell itself. What's not apparent is that the caption on the form (at the top of the screen) is actually not the caption of the Form you see - it's a completely different application. So to get your Form to "float" requires subverting the way the shell handles Form display. A quick and dirty way is to set the Form BorderStyle to none, but then you lose your caption bar. An option then is to manually draw it in with a FillRect and DrawString in OnPaint. Not too difficult and doesn't require any P/Invoke shenanigans, but it does require that you take the new header into consideration when you layout your controls.
这里的挑战是WinMo shell本身。不明显的是表单上的标题(在屏幕顶部)实际上不是您看到的表单的标题 - 它是一个完全不同的应用程序。因此,要使表单“浮动”,需要颠覆shell处理表单显示的方式。一种快速而肮脏的方法是将Form BorderStyle设置为none,但是丢失了标题栏。然后,一个选项是使用OnPaint中的FillRect和DrawString手动绘制它。不太困难,不需要任何P / Invoke恶作剧,但它确实要求您在布局控件时考虑新的标题。
Another option is to use P/Invoke and manipulate the Form's style bits yourself. This works well, but take care that you do it in the right location in code, as some bits have to be set on Window creation. Also beware the shell, as it might want to change the bits back on you - so this mechanism requires more testing and attention to detail. IMO this is a better route, and I've blogged about it in more detail here. That blog entry isn't specifically about floating forms, but it covers style manipulation well. For more specifically on non-fullscreen Forms, see my other blog entry here.
另一种选择是使用P / Invoke并自己操作Form的样式位。这很好用,但请注意在代码中的正确位置执行此操作,因为必须在Window创建时设置一些位。还要注意shell,因为它可能想要改变你的位 - 所以这种机制需要更多的测试和对细节的关注。 IMO这是一条更好的路线,我在这里有更详细的博客。该博客条目并非专门针对浮动表单,但它涵盖了样式操作。有关非全屏表单的更多信息,请参阅此处的其他博客条目。
#2
2
This blog post should help: 'Creating non full screen forms and custom MessageBoxes'.
这篇博文应该有所帮助:'创建非全屏窗体和自定义MessageBoxes'。
#1
2
The challenge here is the WinMo shell itself. What's not apparent is that the caption on the form (at the top of the screen) is actually not the caption of the Form you see - it's a completely different application. So to get your Form to "float" requires subverting the way the shell handles Form display. A quick and dirty way is to set the Form BorderStyle to none, but then you lose your caption bar. An option then is to manually draw it in with a FillRect and DrawString in OnPaint. Not too difficult and doesn't require any P/Invoke shenanigans, but it does require that you take the new header into consideration when you layout your controls.
这里的挑战是WinMo shell本身。不明显的是表单上的标题(在屏幕顶部)实际上不是您看到的表单的标题 - 它是一个完全不同的应用程序。因此,要使表单“浮动”,需要颠覆shell处理表单显示的方式。一种快速而肮脏的方法是将Form BorderStyle设置为none,但是丢失了标题栏。然后,一个选项是使用OnPaint中的FillRect和DrawString手动绘制它。不太困难,不需要任何P / Invoke恶作剧,但它确实要求您在布局控件时考虑新的标题。
Another option is to use P/Invoke and manipulate the Form's style bits yourself. This works well, but take care that you do it in the right location in code, as some bits have to be set on Window creation. Also beware the shell, as it might want to change the bits back on you - so this mechanism requires more testing and attention to detail. IMO this is a better route, and I've blogged about it in more detail here. That blog entry isn't specifically about floating forms, but it covers style manipulation well. For more specifically on non-fullscreen Forms, see my other blog entry here.
另一种选择是使用P / Invoke并自己操作Form的样式位。这很好用,但请注意在代码中的正确位置执行此操作,因为必须在Window创建时设置一些位。还要注意shell,因为它可能想要改变你的位 - 所以这种机制需要更多的测试和对细节的关注。 IMO这是一条更好的路线,我在这里有更详细的博客。该博客条目并非专门针对浮动表单,但它涵盖了样式操作。有关非全屏表单的更多信息,请参阅此处的其他博客条目。
#2
2
This blog post should help: 'Creating non full screen forms and custom MessageBoxes'.
这篇博文应该有所帮助:'创建非全屏窗体和自定义MessageBoxes'。