zoukankan      html  css  js  c++  java
  • (转)C# WinForm 关于窗体最大化时的是否全屏效果与是否遮盖任务栏

    0.新建窗体 及添加按钮

    1.   执行如下按钮事件

    private void btnFormMax_Click(object sender, EventArgs e) 
    {
        if (this.WindowState == FormWindowState.Maximized)
        { 
            this.WindowState = FormWindowState.Normal; 
        } 
        else
        { 
            this.WindowState = FormWindowState.Maximized;
        }
    }

    窗体最大化时 非全屏 不会遮盖任务栏

      此时this.FormBorderStyle 默认为 Sizable

    2.   执行如下按钮事件

    private void btnFormMax_Click(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Maximized)
        {
            this.WindowState = FormWindowState.Normal;
        }
        else
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;
        }
    }

    窗体最大化时 会全屏 及遮盖任务栏

      此时this.FormBorderStyle 为 None 不会显示窗体标题栏等相关

    3.   执行如下按钮事件

    private void btnFormMax_Click(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Maximized)
        {
            this.WindowState = FormWindowState.Normal;
        }
        else
        {
            this.FormBorderStyle = FormBorderStyle.None;
            this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            this.WindowState = FormWindowState.Maximized;
        }
    }

    窗体最大化时 非全屏 不会遮盖任务栏

      此时this.FormBorderStyle 为 None 不会显示窗体标题栏等相关

    [转]窗体最大化的时候,如何指定窗体的位置、大小(C#)

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms;
    namespace WindowsApplication1
    {
        public partial class FormRegion : Form
        {
            private const long WM_GETMINMAXINFO = 0x24;
            public struct POINTAPI
            {
                public int x;
                public int y;
            }
            public struct MINMAXINFO
            {
                public POINTAPI ptReserved;
                public POINTAPI ptMaxSize;
                public POINTAPI ptMaxPosition;
                public POINTAPI ptMinTrackSize;
                public POINTAPI ptMaxTrackSize;
            }
            public FormRegion()
            {
                InitializeComponent();
                this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
            }
            protected override void WndProc(ref System.Windows.Forms.Message m)
            {
                base.WndProc(ref m);
                if (m.Msg == WM_GETMINMAXINFO)
                {
                    MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
                    mmi.ptMinTrackSize.x = this.MinimumSize.Width;
                    mmi.ptMinTrackSize.y = this.MinimumSize.Height;
                    if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
                    {
                        mmi.ptMaxTrackSize.x = this.MaximumSize.Width;
                        mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
                    }
                    mmi.ptMaxPosition.x = 1;
                    mmi.ptMaxPosition.y = 1;
                    System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
                }
            }
        }
    }

    MessageBox.Show("当前窗体标题栏高度"+(this.Height - this.ClientRectangle.Height).ToString());//获得当前窗体标题栏高度 

    ClientRectangle//获取表示控件的工作区的矩形 

    MessageBox.Show(SystemInformation.PrimaryMonitorSize.ToString()); //获取主显示器屏幕的尺寸(像素) 

    //获取主显示器当前当前视频模式的尺寸(以象素为单位) 

    MessageBox.Show("菜单栏高度"+SystemInformation.MenuHeight.ToString()); //获取标准菜单栏的高度 

    MessageBox.Show("标题栏高度"+SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的高度 

    MenuHeight//获取一个菜单行的高度(以象素为单位) 

    CaptionHeight//获取窗口的标准标题栏区域的高度(以象素为单位)

    版权说明:作者:张颖希PocketZ's Blog
    出处:http://www.cnblogs.com/PocketZ
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    若本文为翻译内容,目的为练习英文水平,如有雷同,纯属意外!有不妥之处,欢迎拍砖

  • 相关阅读:
    从《兄弟连》到团队管理
    将来
    [译] TypeScript入门指南(JavaScript的超集)
    基于cocos2dx迷宫游戏
    SVN版本管理教程
    arcgis for android 本地缓存
    vs2010变的特别卡解决办法
    cocos2d-x自适应屏幕
    cocos2d-x使用CCScale9Sprite
    cocos2dx开发入门文档
  • 原文地址:https://www.cnblogs.com/PocketZ/p/1710490.html
Copyright © 2011-2022 走看看