locked
C# Windows Mobile SIP InputPanel: How to Resize my TextBox? RRS feed

  • Question

  • 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 theTextBox 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 thetxtNote.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();
    }
    

      


    ~Joe
    Avoid Sears Home Improvement
    Monday, November 7, 2011 3:09 PM

Answers

  • Hello,

     

    Sorry for delay reply, I found that the txtNote.size is read only, so that you can not change it height directly. But you can change the bounds instead of it. Please follow this codes, and I suggest that the txtNote is dock at bottom.

     

            private void inputPanel1_EnabledChanged(object sender, EventArgs e)
            {
                Rectangle VisibleRect = new Rectangle();
                VisibleRect = this.txtNote.Bounds;
                VisibleRect.Size = this.textBox1.Size;
                if (this.inputPanel1.Enabled == true) //SIP is open 
                {
                    Size si = new Size(this.inputPanel1.VisibleDesktop.Width, 
                        this.inputPanel1.VisibleDesktop.Height);
                    VisibleRect.Size = si;
                    this.txtNote.Bounds = VisibleRect;
                    
                }
                else if (this.inputPanel1.Enabled == false)// SIP is close, restore to the size 
                {
                    Size si = new Size(this.inputPanel1.VisibleDesktop.Width, 
                        VisibleRect.Height - this.inputPanel1.Bounds.Height);
                    VisibleRect.Size = si;
                    this.txtNote.Bounds = VisibleRect;
                    
                }
            }
    

    I hope these information can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by jp2code Tuesday, November 15, 2011 12:37 PM
    Tuesday, November 15, 2011 6:46 AM
  • Just an FYI to others that come here: I had to modify this just a tad to get it to work.

     

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

    Thanks, Jesse!


    ~Joe
    Avoid Sears Home Improvement
    • Marked as answer by Jesse Jiang Wednesday, November 16, 2011 11:20 AM
    Tuesday, November 15, 2011 4:32 PM

All replies

  • Hello,

     

    I test your codes, I think you need to set the textbox's Multiline as True, if this setting is false the height will never increase.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, November 9, 2011 8:22 AM
  • As shown in the pictures (does the rest of the community see the pictures?), the TextBox is already set to Multiline.

    I'm not sure what I am missing.

    Docking the TextBox control to the bottom should not cause any problems, should it?


    ~Joe
    Avoid Sears Home Improvement
    Wednesday, November 9, 2011 1:59 PM
  • Hello,

     

    Sorry for delay reply, I found that the txtNote.size is read only, so that you can not change it height directly. But you can change the bounds instead of it. Please follow this codes, and I suggest that the txtNote is dock at bottom.

     

            private void inputPanel1_EnabledChanged(object sender, EventArgs e)
            {
                Rectangle VisibleRect = new Rectangle();
                VisibleRect = this.txtNote.Bounds;
                VisibleRect.Size = this.textBox1.Size;
                if (this.inputPanel1.Enabled == true) //SIP is open 
                {
                    Size si = new Size(this.inputPanel1.VisibleDesktop.Width, 
                        this.inputPanel1.VisibleDesktop.Height);
                    VisibleRect.Size = si;
                    this.txtNote.Bounds = VisibleRect;
                    
                }
                else if (this.inputPanel1.Enabled == false)// SIP is close, restore to the size 
                {
                    Size si = new Size(this.inputPanel1.VisibleDesktop.Width, 
                        VisibleRect.Height - this.inputPanel1.Bounds.Height);
                    VisibleRect.Size = si;
                    this.txtNote.Bounds = VisibleRect;
                    
                }
            }
    

    I hope these information can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by jp2code Tuesday, November 15, 2011 12:37 PM
    Tuesday, November 15, 2011 6:46 AM
  • Just an FYI to others that come here: I had to modify this just a tad to get it to work.

     

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

    Thanks, Jesse!


    ~Joe
    Avoid Sears Home Improvement
    • Marked as answer by Jesse Jiang Wednesday, November 16, 2011 11:20 AM
    Tuesday, November 15, 2011 4:32 PM