winmobile 中带有文本字段的自定义对话框
我希望有一个简单的自定义对话框,例如消息框,有一个标签和一个文本框。 如果有一个简单的方法可以做到这一点,抱歉! 我真的不太熟悉对话的东西。
谢谢你们的帮助,伙计们!
I'm looking to have a simple custom dialog box, like a message box, that has a label and a TextBox. If there's a simple way to do this, sorry! I'm really not well versed in the dialog stuff.
Thanks for any help, guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是如何在 Windows Mobile 中制作一个如下所示的小型自定义对话框:
替代文本 http://www.freeimagehosting。 net/uploads/b8fb5421d6.jpg
将表单添加到您的项目中,并将其 FormBorderStyle 属性设置为 None。 这允许调整表单的大小和位置,但也意味着它没有边框或标题栏,并且用户无法移动它。
所以你必须伪造这三个。 伪造边框和标题栏的最简单方法是制作窗体的 BackColor SystemColors.WindowFrame,然后放置一个标签(图片中显示“对话框”的位置),其中 BackColor = SystemColors.Highlight 和 ForeColor = SystemColor.HighlightText (并将字体加粗),然后在图片中看到白色的地方放置一个带有 BackColor = SystemColors.Window 的面板。 您必须调整标签和面板的位置和大小,以便获得 1 像素边框(这只是显示出来的表单的背景色)。
要使表单能够通过其假标题栏拖动,请将此代码添加到表单中(当然,您也必须连接事件):
另一个问题是,因为没有真正的标题栏,所以没有用户关闭表单的方式。 您必须添加一个“确定”(或“关闭”)按钮,并将其放入该按钮的 Click 事件中:
通常您会在标题栏上使用鼠标事件以方便拖动,但标签控件没有任何鼠标事件。 使用此代码,您实际上可以抓取表单上的任何位置并拖动它,但面板会阻止此操作并使标题栏成为唯一抓取和拖动的位置。
我的另一个答案提供了有关从自定义对话框获取信息的更多详细信息。
更新:实际上,没有明显的方法可以在不添加自己的“确定”按钮的情况下关闭无边框表单。 只要您不将窗体的 ControlBox 属性设置为 False,“今日”屏幕右上角的“确定”或“X”按钮就会关闭您的对话框,即使它看起来不像会关闭,因为它实际上不在屏幕上。形式。
Here is how to make a small custom dialog box in Windows Mobile that looks like this:
alt text http://www.freeimagehosting.net/uploads/b8fb5421d6.jpg
Add a form to your project, and set its FormBorderStyle property to None. This allows the form to be resized and positioned, but also means it has no border or titlebar, and there's no way for the user to move it.
So you have to fake all three. The easiest way to fake the border and the title bar is to make the BackColor of your form SystemColors.WindowFrame, then put a label (where it says "Dialog" in the picture) with BackColor = SystemColors.Highlight and ForeColor = SystemColor.HighlightText (and bold the font), then put a panel with BackColor = SystemColors.Window where you see white in the picture. You have to tweak the positions and sizes of the label and the panel so you have a 1-pixel border (which is just the BackColor of your form showing through).
To enable the form to be dragged around by its fake titlebar, add this code to the form (and of course you have to wire up the events, too):
One other problem is that because there isn't a real titlebar, there's no way for the user to close the form. You have to add an OK (or Close) button, and put this in the button's Click event:
Normally you would use the mouse event on the title bar to facilitate dragging, but the label control doesn't have any mouse events. With this code you could actually grab anywhere on the form and drag it, except the panel blocks this and makes the title bar the only place to grab and drag.
My other answer has more details on getting information back from custom dialogs.
Update: actually, there's only no obvious way to close a borderless form without adding your own OK button. As long as you don't set your form's ControlBox property to False, the OK or X button in the upper right corner of the Today screen will close your dialog, even if it doesn't look like it will since it's not actually on the form.
如果您想要一个超级简单但丑陋的解决方案,您可以在项目中包含对 Microsoft.VisualBasic 的引用,它允许您使用 VB 函数 InputBox,如下所示:
该对话框占据整个屏幕,但很容易使用。 但正如我提到的,它非常丑陋。
If you want a super-simple but[t] ugly solution, you can include a reference in your project to Microsoft.VisualBasic, which lets you use the VB function InputBox like this:
The dialog takes up the entire screen, but is simple to use. But is incredibly ugly, as I mentioned.
我假设您基本上想要一个返回用户输入的字符串的自定义对话框。 一种方法是将 Microsoft.VisualBasic 的引用添加到您的项目中,这使您可以访问 InputBox 方法,该方法基本上是一个带有文本框的消息框。 但这一点也不有趣,而且我不确定它是否能在智能手机上运行。
要推出自己的表单,只需将一个表单(名为 CustomDialog)添加到项目中,然后将一个文本框 (textBox1)、一个标签 (label1) 和一个按钮(标记为“OK”)拖到其上。
要设置标签文本,请向表单的构造函数添加一个参数,如下所示:
要向调用者公开输入的文本,请将此代码添加到表单中:
在“确定”按钮的单击事件中,输入以下代码:
要从主窗口使用此对话框表单,您创建此表单的一个实例,显示它,检查是否单击了“确定”按钮,然后读取其 Text 属性(返回用户输入的内容),如下所示:
您可以变得更奇特,但这些是基础知识。
I'm assuming you basically want a custom dialog box that returns a string entered by the user. One way is to add a reference to Microsoft.VisualBasic to your project, which gives you access to the InputBox method, which is basically a message box with a text box on it. But that's no fun and I'm not sure it would work on a smartphone anyway.
To roll your own, you just add a form (named CustomDialog) to your project and drag a textbox (textBox1), a label (label1), and a button (labeled "OK") onto it.
To set the label text, add a parameter to the form's constructor like this:
To expose the entered text to the caller, add this code to the form:
In the OK button's click event, put this code:
To use this dialog from your main form, you create an instance of this form, show it, check to see that the OK button was clicked, and then read its Text property (which returns what the user entered) like so:
You can get fancier, but those are the basics.