WinForm隐藏和显示问题? [英] WinForm Hide and Show problem?

查看:311
本文介绍了WinForm隐藏和显示问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在表单隐藏和显示期间遇到问题,问题是: - 当windows state属性设置为正常时,我的两个表单都打开了,当我们设置的属性是最大化的,所以代码运行正常,只有一个表单显示。



请帮帮我。



提前致谢。



问候

Ankit Agarwal

软件工程师

Hello,

I am getting problem during form hide and show, problem is:- when windows state property set on normal so,my both form opened, when we set property is Maximized so, code is correct running, only one form show.

please help me.

Thanks in Advance.

Regards
Ankit Agarwal
Software Engineer

推荐答案

phil.o和Wes Aday说的是真的 - 你见证的行为是预期的。



但是,如果你限制每个表单的大小,然后您可以控制表单最大化时占用的桌面格局的大小。实现此目的的一种方法是重写OnSizeChanged事件处理程序。以下应用程序演示了此解决方案。

What phil.o and Wes Aday stated is true - the behavior you witness is expected.

However, if you limit the size of each form, then you can control how much of the desktop landscape the forms will occupy when they are maximized. One way you achieve this is by overriding the OnSizeChanged event handler. The following application demonstrates this solution.
using System;
using System.Windows.Forms;

namespace MaximizeWindowOverride
    {

    public partial class Form1 : Form
        {

        // ******************************************* class constants

        const int       MAXIMUM_HEIGHT = 500;
        const int       MAXIMUM_WIDTH = 600;

        // ******************************************* class variables

        FormWindowState current_window_state;

        // ***************************************************** Form1

        public Form1 ( )
            {

            InitializeComponent ( );

            current_window_state = this.WindowState;
            }

        // ********************************************* OnSizeChanged
        
        protected override void OnSizeChanged ( EventArgs e )
            {

            base.OnSizeChanged ( e );

            if ( ( this.WindowState == FormWindowState.Maximized ) &&
                 ( current_window_state != FormWindowState.Maximized ) )
                {
                this.Width = MAXIMUM_WIDTH;
                this.Height = MAXIMUM_HEIGHT;

                this.WindowState = FormWindowState.Normal;
                }

            current_window_state = this.WindowState;
            }

        } // class Form1

    } // namespace MaximizeWindowOverride



希望有所帮助。


Hope that helps.


这篇关于WinForm隐藏和显示问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆