2010-10-07 68 views
1

我正在用C#開發移動應用程序。我正在使用鍵盤啓動功能在移動設備上的某個文本框得到關注時啓動鍵盤。我正在使用下面的代碼。如何在移動應用程序中動態調整窗體大小?

private void inputPanel1_EnabledChanged(object sender, EventArgs e) 
     { 
      InputEnabled(); 
     } 

     private void InputEnabled() 
     { 
      int y; 

      if (inputPanel1.Enabled) 
       // SIP visible - position label just above the area covered by the input panel 
       y = Height - inputPanel1.Bounds.Height; 
      else 
       // SIP not visible - position label just above bottom of form 
       y = Height; 

      // Calculate the position of the top of the label 
      //y = y - mainPanel.Height; 
      //this.Dock = DockStyle.Top; 
      //mainPanel.Location = new Point(0, y); 
      this.Size = new Size(this.Size.Width, y); 
      this.AutoScroll = true; 

      //this.AutoScrollPosition = new Point(this.AutoScrollPosition.X, descriptionTextBox.Location.Y); 
     } 

在上面的代碼中,我試圖動態改變窗體的高度。我在應用程序中添加了斷點。在以下聲明中

this.Size = new Size(this.Size.Width, y); 

我可以看到y的值在右側變爲180。但在左側,這個this.Size的值保持不變。我完全不知道爲什麼會發生這種情況。你能告訴我在我的代碼中有什麼不對嗎,或者你能否給我提供解決方案,以便左邊的this.size語句中的高度值得到改變?

回答

2

在WinMobile應用程序中修改表單大小可能會非常棘手,如果不是絕對必要的話,我寧願避免它。

在這種情況下,您可以將控件放置到面板中並調整面板大小,而不是調整窗體大小。您還可以使用該方法在這裏使用軟輸入面板:http://www.christec.co.nz/blog/archives/42

調整停靠到窗體底部 面板是相同的高度 的SIP。這會將其他控件 也停靠在表單 的底部,使其高於SIP所涵蓋的區域。

+0

關於該主題的另一個鏈接:http://stackoverflow.com/questions/2266518/how-to-automatically-resize-a-windows-mobile-application-when-the-keyboard-appear – Yakimych 2010-10-07 14:18:52

相關問題