如何在移动应用程序中动态调整窗口窗体的大小?

发布于 2024-09-26 16:01:43 字数 1243 浏览 12 评论 0原文

我正在用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2024-10-03 16:01:43

在 WinMobile 应用程序中修改表单大小可能很棘手,如果不是绝对必要,我宁愿避免这样做。

在这种情况下,您可以将控件放入面板中并调整面板大小,而不是调整表单大小。您还可以在此处使用软输入面板的方法:http://www.christec .co.nz/blog/archives/42

调整停靠在底部的面板的大小
表格的高度与
SIP。这会移动其他控件
也停靠在表单的底部
高于所覆盖的区域
SIP。

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

Resize the panel docked to the bottom
of the form to be the same height as
the SIP. This moves other controls
also docked to the bottom of the form
to be above the area covered by the
SIP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文