Search code examples
c#visual-studio-2008windows-mobilecompact-framework

C# Windows Mobile SIP InputPanel: How to resize my TextBox?


Using the Soft Input Panel (SIP) to enter text on my C# WinMobile CF 2.0 application.

There is a textbox at the bottom that I want to enlarge whenever the SIP is pressed.

The SIP is called correctly whenever the TextBox receives focus, but I can't seem to get the TextBox to grow enough to see the text.

The TextBox is docked to the bottom.

I've placed breakpoints in my code, and the SIP_EnabledChanged routine is being hit and the txtNote.Size is being changed ...but the size of my TextBox does not change on the display.

Why?

using Microsoft.WindowsCE.Forms;

int startH = txtNote.Size.Height;
// (In the designer):
this.inputPanel1.EnabledChanged += new System.EventHandler(this.SIP_EnabledChanged);

void Form1_Load(object sender, EventArgs e) {
  inputPanel1.Enabled = false;
  startH = txtNote.Size.Height;
}

void SIP_EnabledChanged(object sender, EventArgs e) {
  SuspendLayout();
  int height = inputPanel1.Enabled ? startH + 80 : startH;
  txtNote.Size = new Size(txtNote.Size.Width, height);
  ResumeLayout();
}

TextBox displayed SIP displayed


Solution

  • Got an answer on MSDN >> HERE << yesterday that I was able to modify to work.

    The key, apparently, is to set the Bounds, not the Size or the Location.

    Here is what I went with:

    int startY;
    
    void Form1() : Form {
      InitializeComponent();
      startY = txtNote.Location.Y; // only set here.
    }
    // Method below fires whenever the Soft Input Panel changes
    void SIP_EnabledChanged(object sender, EventArgs e) {
      int locationY = startY;
      if (inputPanel1.Enabled) {
        locationY -= inputPanel1.Bounds.Height;
      }
      txtNote.SuspendLayout();
      // setting the Bounds was the key to getting this to work!
      txtNote.Bounds = new Rectangle(
        txtNote.Location.X,
        locationY,
        txtNote.Size.Width,
        txtNote.Size.Height
      );
      txtNote.ResumeLayout();
      txtNote.Refresh();
    }
    

    I hope that posting the solution helps someone, one day.