LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

C# 双击鼠标全屏显示或全窗口显示 恢复

admin
2024年12月27日 23:59 本文热度 104

用控件panel1全屏显示;panel2全窗口显示

通过panel1、panel事件MouseDoubleClick实现。

遮盖panel1上的控件属性的Enabled设置为false,避免捕捉不到双击。

显示界面如下:

代码:

using System.Runtime.InteropServices;

namespace 双击全屏显示或恢复

{

    public partial class Form1 : Form

    {

        [DllImport("user32.dll", SetLastError = true)]

        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

        [DllImport("user32.dll", SetLastError = true)]

        static extern IntPtr GetDesktopWindow();

        [DllImport("user32.dll", SetLastError = true)]

        static extern IntPtr GetParent(IntPtr hWnd);

        [DllImport("user32.dll", SetLastError = true)]

        static extern int GetSystemMetrics(int nIndex);

        [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]

        public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);

        [DllImport("User32.dll ", EntryPoint = "FindWindow")]

        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        public int SW_HIDE = 0;

        public int SW_RESTORE = 9;

        public bool m_bIsFullScreen = false;//判断是否全屏

        public bool m_bIsFillDock = false;//判断是否全容器

        Rectangle m_RecPanel1 = new Rectangle();//获取原始大小

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            m_RecPanel1 = panel1.Bounds;//获得panel1原始Bounds范围大小

        }

        //控件panel1全屏显示

        private void panel1_MouseDoubleClick(object sender, MouseEventArgs e)

        {

            if (!m_bIsFullScreen)

            {

                //获取桌面窗口并设置为父窗口

                IntPtr hDesk = GetDesktopWindow();

                SetParent(this.panel1.Handle, hDesk);

                int width = GetSystemMetrics(0);

                int height = GetSystemMetrics(1);

                this.panel1.Dock = DockStyle.None;//这个很重要,Anchor属性仍可用

                this.panel1.Bounds = new Rectangle(new Point(0, 0), new Size(width, height));

                ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);//隐藏Windows任务栏

                //ShowWindow(FindWindow("Button", null), SW_HIDE);

                m_bIsFullScreen = true;

            }

            else

            {

                //获取桌面窗口并设置为父窗口

                IntPtr hDesk = GetDesktopWindow();

                SetParent(this.panel1.Handle, this.Handle);

                int width = GetSystemMetrics(0);

                int height = GetSystemMetrics(1);

                this.panel1.Dock = DockStyle.None;//这个很重要,Anchor属性仍可用

                this.panel1.Bounds = m_RecPanel1;

                ShowWindow(FindWindow("Shell_TrayWnd", null), SW_RESTORE);//Shell_TrayWnd是任务栏的类名

                m_bIsFullScreen = false;

            }

        }

        //全窗口显示

        //也可以用全屏的方法将   panel2.Bounds=窗口的大小;

        private void panel2_MouseDoubleClick(object sender, MouseEventArgs e)

        {

            if (!m_bIsFillDock)

            {

                this.panel2.Parent = this;//以窗口为父控件

                this.panel2.Dock = DockStyle.Fill;//填充至整个父控件大小

                panel2.BringToFront();//可以没有,用来保证panel2在最前面,但是还原时候会遮盖原来在上面的控件

                m_bIsFillDock = true;

            }

            else

            {

                this.panel2.Parent = this;

                this.panel2.Dock = DockStyle.None;

                //panel2.BringToFront();

                m_bIsFillDock = false;

            }

        }

    }

}

源代码下载链接:

https://share.weiyun.com/imRUNgZj


该文章在 2024/12/28 11:57:28 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved