C# 实现WinForm 全屏

来源:互联网 发布:单片机常用芯片51 编辑:程序博客网 时间:2024/05/27 01:37
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace WindowsFormsApplication3{    public partial class Form1 : Form    {        ///   <summary>           [DllImport("user32.dll")]        public static extern int FindWindow(            string lpClassName,             //   class   name               string lpWindowName             //   window   name           );        [DllImport("user32.dll")]        public static extern bool SetWindowPos(            int hWnd,                           //   handle   to   window               int hWndInsertAfter,                //   placement-order   handle               int X,                              //   horizontal   position               int Y,                              //   vertical   position               int cx,                             //   width               int cy,                             //   height               uint uFlags                         //   window-positioning   options           );        /// <summary>        /// 显示和隐藏鼠标指针.        /// </summary>        [DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)]        public static extern int ShowCursor(int bShow);        const int SWP_NOSIZE = 0x1;        const int SWP_NOMOVE = 0x2;        const int SWP_NOZORDER = 0x4;        const int SWP_NOREDRAW = 0x8;        const int SWP_NOACTIVATE = 0x10;        const int SWP_FRAMECHANGED = 0x20;                 //The frame changed:send WM_NCCALCSIZE           const int SWP_SHOWWINDOW = 0x40;        const int SWP_HIDEWINDOW = 0x80;        const int SWP_NOCOPYBITS = 0x100;        const int SWP_NOOWNERZORDER = 0x200;               // Don't do owner Z ordering           const int SWP_DRAWFRAME = SWP_FRAMECHANGED;        const int SWP_NOREPOSITION = SWP_NOOWNERZORDER;        // SetWindowPos()   hwndInsertAfter   values           const int HWND_TOP = 0;        const int HWND_BOTTOM = 1;        const int HWND_TOPMOST = -1;        const int HWND_NOTOPMOST = -2;        private int hTaskBar;           public Form1()        {            InitializeComponent();            this.WindowState = FormWindowState.Maximized;            this.FormBorderStyle = FormBorderStyle.None;            this.StartPosition = FormStartPosition.CenterScreen;            //this.Size=SystemInformation.PrimaryMonitorSize;            this.hTaskBar = FindWindow("Shell_traywnd", null);           }        private void Form1_Load(object sender, EventArgs e)        {                       SetWindowPos(this.hTaskBar, HWND_BOTTOM, 0, 0, 0, 0, SWP_HIDEWINDOW);                       ShowCursor(0);        }        private void Form1_FormClosing(object sender, FormClosingEventArgs e)        {            SetWindowPos(this.hTaskBar, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW);        }        private void Form1_MouseHover(object sender, EventArgs e)        {            ShowCursor(1);        }    }}
原创粉丝点击