最近接手做一个基于Winform的仓库管理系统,希望把程序主界面窗口做成全屏且不可拖动不可调整大小的效果,原先以为设置FormBorderStyle为FixedDialog,设置WindowState为Maximized就可以了,但发现除了窗口可移动以外,而且通过双击标题栏窗口还是被还原为了设计时的Size大小,更槽糕的是Winfom在FixedDialog和Maximized模式下运行操作系统的任务栏都被盖住了。
这时候想到重写WinForm的OnSizeChanged方法,让它不执行任何操作。
 protected override void OnSizeChanged(EventArgs e)
    protected override void OnSizeChanged(EventArgs e)
 {
    {
 return;
        return;
 }
    郁闷的是仍然没有作用,只好上网去找了找,相比Web技术来说,我发现找windows开发的资源要困难的多,看来现在做winform的越来越少了,园子里的winform的资料也比较少。网上有许多人都碰到类似的问题,但没合适的.net的解决方案,C++,VB的倒有,都是需要捕获windows消息的。呵呵,也许.net也可以做到,只是我对这方面了解并不深入。
    }
    郁闷的是仍然没有作用,只好上网去找了找,相比Web技术来说,我发现找windows开发的资源要困难的多,看来现在做winform的越来越少了,园子里的winform的资料也比较少。网上有许多人都碰到类似的问题,但没合适的.net的解决方案,C++,VB的倒有,都是需要捕获windows消息的。呵呵,也许.net也可以做到,只是我对这方面了解并不深入。
最后自己想了一个解决办法,仍然设置FormBorderStyle为FixedDialog,在form加载时动态设置Form达到全屏效果(通过设置form的top,left,height,width),然后处理其Location_Changed事件使其顶点永久居于Screen(0,0)位置。 private void AppMain_Load(object sender, EventArgs e)
        private void AppMain_Load(object sender, EventArgs e)
 {
        {
 InitForm();
            InitForm();
 }
        }

 void InitForm()
        void InitForm()
 {
        {
 this.Top = 0;
            this.Top = 0;
 this.Left = 0;
            this.Left = 0;
 this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height;
 this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Width = Screen.PrimaryScreen.WorkingArea.Width;
 Global.NavigatorForm = new Navigator();
            Global.NavigatorForm = new Navigator();
 Global.NavigatorForm.Show();
            Global.NavigatorForm.Show();
 }
        }

 private void AppMain_FormClosing(object sender, FormClosingEventArgs e)
        private void AppMain_FormClosing(object sender, FormClosingEventArgs e)
 {
        {
 if (e.CloseReason == CloseReason.UserClosing)
            if (e.CloseReason == CloseReason.UserClosing)
 {
            {
 if (DialogResult.Yes == WindowUtil.Confirm("您确定要退出应用程序吗?"))
                if (DialogResult.Yes == WindowUtil.Confirm("您确定要退出应用程序吗?"))
 {
                {
 Application.Exit();
                    Application.Exit();
 }
                }
 else
                else
 {
                {
 e.Cancel = true;
                    e.Cancel = true;
 }
                }
 }
            }
 }
        }

 private void AppMain_LocationChanged(object sender, EventArgs e)
        private void AppMain_LocationChanged(object sender, EventArgs e)
 {
        {
 this.Left = 0;
            this.Left = 0;
 this.Top = 0;
            this.Top = 0;
 }
        }
这时候想到重写WinForm的OnSizeChanged方法,让它不执行任何操作。
 protected override void OnSizeChanged(EventArgs e)
    protected override void OnSizeChanged(EventArgs e) {
    { return;
        return; }
    }最后自己想了一个解决办法,仍然设置FormBorderStyle为FixedDialog,在form加载时动态设置Form达到全屏效果(通过设置form的top,left,height,width),然后处理其Location_Changed事件使其顶点永久居于Screen(0,0)位置。
 private void AppMain_Load(object sender, EventArgs e)
        private void AppMain_Load(object sender, EventArgs e) {
        { InitForm();
            InitForm(); }
        }
 void InitForm()
        void InitForm() {
        { this.Top = 0;
            this.Top = 0; this.Left = 0;
            this.Left = 0; this.Height = Screen.PrimaryScreen.WorkingArea.Height;
            this.Height = Screen.PrimaryScreen.WorkingArea.Height; this.Width = Screen.PrimaryScreen.WorkingArea.Width;
            this.Width = Screen.PrimaryScreen.WorkingArea.Width; Global.NavigatorForm = new Navigator();
            Global.NavigatorForm = new Navigator(); Global.NavigatorForm.Show();
            Global.NavigatorForm.Show(); }
        }
 private void AppMain_FormClosing(object sender, FormClosingEventArgs e)
        private void AppMain_FormClosing(object sender, FormClosingEventArgs e) {
        { if (e.CloseReason == CloseReason.UserClosing)
            if (e.CloseReason == CloseReason.UserClosing) {
            { if (DialogResult.Yes == WindowUtil.Confirm("您确定要退出应用程序吗?"))
                if (DialogResult.Yes == WindowUtil.Confirm("您确定要退出应用程序吗?")) {
                { Application.Exit();
                    Application.Exit(); }
                } else
                else {
                { e.Cancel = true;
                    e.Cancel = true; }
                } }
            } }
        }
 private void AppMain_LocationChanged(object sender, EventArgs e)
        private void AppMain_LocationChanged(object sender, EventArgs e) {
        { this.Left = 0;
            this.Left = 0; this.Top = 0;
            this.Top = 0; }
        } 
                     
                    
                 
                    
                 
 
    
 
             posted on
 posted on 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号