Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom dialog with a text field in 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!

like image 805
Matthew Avatar asked Dec 18 '22 10:12

Matthew


1 Answers

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

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;
    }
}

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.

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.

like image 141
MusiGenesis Avatar answered Dec 19 '22 22:12

MusiGenesis