开发者

.NET CF -- Set Form height based on InputPanel state

So, I've got a C# project for Windows Mobile phones and I'm trying to work with the InputPanel. Specifically, I've got one form with a stack of Labels and TextBoxes that collect user in开发者_如何学编程put. I have an InputPanel that alerts me when the user opens the SIP. Everything works fine so far. When I get messages that the SIP status has changed, I want to change the height of the Form, which doesn't seem possible.

Here's my event handler for my InputPanel:

void m_InputPanel_EnabledChanged(object sender, EventArgs e)
{
    // :(  this assignment operation doesn't work and it doesn't               
    this.ClientSize = inputPanel1.VisibleDesktop.Size;
    // doesn't work
    this.Size = inputPanel1.VisibleDesktop.Size;
    // assignment operation works, but isn't very useful
    this.visibleHeight = inputPanel1.VisibleDesktop.Height;
    this.InitializeUI();
}

When I say that the assignment operation doesn't work, I mean that the values don't change in the debugger. I can understand that maybe I can't change the size of a Form, but I can't understand why trying to change it wouldn't throw an exception, or give a compiler error.

I have my Form WindowState set to Normal instead of Maximized, but it doesn't make a difference.

Also, I have read http://www.christec.co.nz/blog/archives/42 this page that tells me how I'm supposed to do this, but I can't easily put all of my controls in a Panel because I'm using a bunch of custom stuff to do alpha background controls.


Changing the height and width of a form in .NET CF has no effect whatsoever, unless its FormBorderStyle is set to None.

However, doing this isn't a good idea in your case, since you don't actually want a borderless form. The proper thing to do in your case is to put all of your controls (labels and textboxes) on a Panel (which is sitting on your form, of course), and then resize the panel as the SIP opens and closes.

Edit: Since I've seen this kind of interface in Windows Mobile, please allow me to give you some unsolicited UI advice. Rule #1 for me with .NET CF applications is: "never use the SIP under any circumstances". The SIP is, of course, completely unusable without a stylus, and not very much use with a stylus, especially with an even slightly out-of-alignment screen.

If you must break Rule #1 (and of course, you have to break this rule for most kinds of free-form text input), then your UI should at least be polite to the user and do two things:

  1. Don't continually resize and rearrange your form in response to the SIP opening and closing. If your form requires the SIP, leave permanent space at the bottom to accomodate it.
  2. Don't make the user open and close the SIP. If your form requires the SIP, open the SIP when your form loads, and close the SIP when your form closes.

Finally, I've generally found it easier to use static methods like this rather than adding an InputControl to each of my forms. I find InputControls to be a pain, and sometimes they get in each other's way if you have more than one form with an InputControl on it open at the same time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜