views:

694

answers:

2

I'm looking into Windows Mobile development but there is one thing which I haven't quite figured out yet. In all applications already installed on the device (Internet Explorer, configuration windows, etc) whenever the on-screen (soft?) keyboard appears, the user interface automatically resizes so the keyboard doesn't cover or obscure the user interface (and if necessary it adds scroll bars).

However when I simply add a text box to my Windows Mobile form, somewhere near the bottom, and test it, it's not automatically resized. The keyboard covers the text box and I can no longer see what I am typing.

Is there a way to automatically do this, or should I do this myself using an InputPanel control and listening for its event?

This is all with .NET (the compact framework, I believe), C# and Windows Mobile Professional 6.1, by the way.

+2  A: 

Use the InputPanel component. It contains a EnabledChanged event. Simply handle the event and resize/hide/show your controls. :)

Example code can be found at the MSDN.

Rhapsody
In my opinion this is not necessary, as 99% percent of the layout changes can be achieved through proper use of the Dock and Anchor properties.
Thorsten Dittmar
With the anchor/dock properties you can resize the controls automatically when the screen resizes, but does this also work when a SIP is displayed/hidden? I'm not able to test it over here, but I thought that in this case, the anchor/dock solution would not work.
Rhapsody
Yes, because showing the SIP resizes the form, so controls anchored to the bottom of the form will change their size/position accordingly. I've used it several times.
Thorsten Dittmar
@Rhapsody: Sorry, I have to revoke what I said. Does work for rotating the form, but not for showing the SIP.
Thorsten Dittmar
@Thorsten @pbean Ok, good to be sure now, so I think the only solution is to use the EnabledChanged event of the InputPanel control.
Rhapsody
+1  A: 

You will have to set the Anchor property for the control respectively. The form will be resized automatically because it is full-screen, but unless you tell your control to be anchored to the bottom, it will not move but be "outside" the form.

Example: You have a "fill client area" ListView and two buttons below that ListView. To make the ListView adjust its size and move the buttons according to the new height, set the ListView's anchor property to "Top, Left, Bottom, Right" and the buttons` anchor property to "Bottom, Left" and "Bottom, Right". That way you also account for screen rotation in that the controls resize/move correctly.

You'd have to listen to the InputPanel events only in case you want to entirely restructure your layout when the SIP is shown/hidden.

Thorsten Dittmar
(Sorry for the belated reply). I tried what you suggested, but unfortunately it does not work. When I have a panel stretched out over the full size of the form and have the Anchor set to Top, Left, Bottom, Right it does not resize at all when the soft keyboard appears.
pbean
Try the following: Remove the panel and put a Label on the form, move it to the bottom. Set Anchor for the Label to "Bottom, Left", The label should move up and still be visible when you show the SIP. This works for me in various situations.
Thorsten Dittmar
That works, but it's not entirely usable in my current sitation. To show different parts of the user interface, I use user controls which I put on the form. But using the Anchor isn't actually working with this (just like with a panel).
pbean
Hm. Seems I've got it wrong this time. My "Anchor" suggestion works fine when rotating the form (this changes the size of the form), but it does actually not work when showing the SIP. I guess you have to manually resize your controls using the "VisibleDesktop" property of the InputPanel control... Sorry to have insisted on a non-functional solution :-(
Thorsten Dittmar