在winmobile文本字段的自定义对话框 [英] custom dialog with a text field in winmobile

查看:162
本文介绍了在winmobile文本字段的自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待有一个简单的自定义对话框,像一个消息框,有一个标签和一个TextBox。如果有一个简单的方法来做到这一点,对不起!我真的没有在该对话框的东西样样精通。

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!

推荐答案

下面是如何要在Windows Mobile的一个小的自定义对话框,如下所示:

Here is how to make a small custom dialog box in Windows Mobile that looks like this:

替换文本/

将窗体添加到您的项目,并设置其FormBorderStyle属性为None。这样的形式来调整大小和位置,也意味着它没有边框或标题栏,而且也没有办法让用户移动它。

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.

所以,你必须假的所有三个。假边框和标题栏的最简单的方法就是让你的表单SystemColors.WindowFrame的背景色,然后把一个标签(它说:对话框中的图片)与背景色= SystemColors.Highlight和前景色= SystemColor.HighlightText (和大胆的字体),然后把背景色用= SystemColors.Window在那里你看到图片中白色的面板。你必须让你有一个1像素的边框(这只是你的表格显示了通过的背景色)来调整立场和标签大小和面板。

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):

private bool _Moving = false;
private Point _Offset;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
    _Moving = true;
    _Offset = new Point(e.X, e.Y);
}

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    if (_Moving)
    {
        Point newlocation = this.Location;
        newlocation.X += e.X - _Offset.X;
        newlocation.Y += e.Y - _Offset.Y;
        this.Location = newlocation;
    }
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
    if (_Moving)
    {
        _Moving = false;
    }
}



另外一个问题是,由于没有一个真正的标题栏,也没有办法为用户关闭表单。你必须添加一个OK(或关闭)按钮,并把这个按钮的Click事件:

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:

this.DialogResult = DialogResult.OK;



通常你会使用标题栏中的鼠标事件,以方便拖动,但标签控件没有按'吨有任何鼠标事件。有了这个代码,你实际上可以在表单上的任何地方抓住并拖动它,除了面板阻止此,使标题栏抓住并拖动的地方。

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.

更新:其实,这里只有没有的明显的方式来关闭一个无国界的形式无添加你自己确定按钮。只要你不窗体的ControlBox属性设置为False,在今日屏幕右上角的确定或X按钮将关闭您的对话,即使它看起来并不像它会因为它不是真正的形式。

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.

这篇关于在winmobile文本字段的自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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