如何在移动应用程序中动态调整窗口窗体的大小?
我正在用 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 语句中的高度值?
I am developing mobile application in C#. I am using the keyboard launch functionality to launch the keyboard on mobile device when one of the textbox gets focused. I am using the following code.
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);
}
In the above code I am trying to change the height of windows form dynamically. I have added breakpoint in my application. In the following statement
this.Size = new Size(this.Size.Width, y);
I can see the value of y gets changed to 180 in right side. But in the left side the value of this this.Size remains unchanged. I am totally unaware why this is happening. Can you please tell me is anything wrong in my code or can you provide me the solution so that the value of height in the this.size statement on the left side gets changed ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 WinMobile 应用程序中修改表单大小可能很棘手,如果不是绝对必要,我宁愿避免这样做。
在这种情况下,您可以将控件放入面板中并调整面板大小,而不是调整表单大小。您还可以在此处使用软输入面板的方法:http://www.christec .co.nz/blog/archives/42
Modifying the form size in a WinMobile application could be tricky and I would rather avoid it if not absolutely necessary.
In this case, instead of resizing the form you can place your controls into a panel and resize the panel. You can also use the approach for using a soft input panel here: http://www.christec.co.nz/blog/archives/42