winform窗体全屏
bool fullscreen = false;
Rectangle rect = new Rectangle();
private void button4_Click(object sender, EventArgs e)
{
fullscreen = !fullscreen;//循环。点一次全屏,再点还原。
SetFullScreen(fullscreen, ref rect);
if (fullscreen)
{
this.WindowState = FormWindowState.Maximized;//全屏
}
else
{
this.WindowState = FormWindowState.Normal;//还原
}
}
/// <summary>
/// 设置全屏或这取消全屏
/// </summary>
/// <param name="fullscreen">true:全屏 false:恢复</param>
/// <param name="rectOld">设置的时候,此参数返回原始尺寸,恢复时用此参数设置恢复</param>
/// <returns>设置结果</returns>
public static bool SetFullScreen(bool fullscreen, ref Rectangle rectOld)
{
int Hwnd = 0;
Hwnd = FindWindow("Shell_TrayWnd", null);
if (Hwnd == 0) return false;
if (fullscreen)
{
ShowWindow(Hwnd, SW_HIDE);
Rectangle rectFull = Screen.PrimaryScreen.Bounds;
SystemParametersInfo(SPI_GETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);//get
SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectFull, SPIF_UPDATEINIFILE);//set
}
else
{
ShowWindow(Hwnd, SW_SHOW);
SystemParametersInfo(SPI_SETWORKAREA, 0, ref rectOld, SPIF_UPDATEINIFILE);
}
return true;
}
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
public const int SW_SHOW = 5; public const int SW_HIDE = 0;
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
private static extern int SystemParametersInfo(int uAction, int uParam, ref Rectangle lpvParam, int fuWinIni);
public const int SPIF_UPDATEINIFILE = 0x1;
public const int SPI_SETWORKAREA = 47;
public const int SPI_GETWORKAREA = 48;
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class WindowsFullScreenApi
{
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int which);
[DllImport("user32.dll")]
public static extern void
SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter,
int X, int Y, int width, int height, uint flags);
private const int SM_CXSCREEN = 0;
private const int SM_CYSCREEN = 1;
private static IntPtr HWND_TOP = IntPtr.Zero;
private const int SWP_SHOWWINDOW = 64; // 0x0040
public static int ScreenX
{
get { return GetSystemMetrics(SM_CXSCREEN); }
}
public static int ScreenY
{
get { return GetSystemMetrics(SM_CYSCREEN); }
}
public static void SetWinFullScreen(IntPtr hwnd)
{
SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW);
}
}
调用::全屏
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
WindowsFullScreenApi.SetWinFullScreen(Handle);
调用::恢复
FormBorderStyle = FormBorderStyle.Sizable;
WindowState = FormWindowState.Maximized;//自己控制恢复后是什么状态
winform窗体全屏的更多相关文章
- C#窗体全屏功能
最近有朋友让我给他弄个应用程序全屏的功能,例如银行的取号程序界面.所以我从网上查询了一些实现的方法. C#应用程序中如何实现全屏幕显示功能? 效果就像windows自带的屏幕保护程序和众多的游戏那样, ...
- C#实现窗体全屏
方法一:设置窗体属性 //程序启动路径,与生成程序的exe文件在同一目录下 public String exePath = Application.StartupPath; //定义窗体宽高 ; ; ...
- Delphi7 实现窗体全屏方法
设置要全屏的窗体的ALign 属性为ALcLient ,此法最快.当然对我来说,我并不知道这个,所以走了远路,等后来在实现窗体禁止移动的时候才想到了这里,汗.注意:这种全屏方式不会挡了系统的任务栏.. ...
- qt中窗体全屏
原文地址:https://www.cnblogs.com/wiessharling/p/3750461.html 近期在学习QT时遇到了很多问题这也是其中一个,个人通过在各种书籍和网络上的查阅找到了一 ...
- Winform 界面全屏 显示状态栏
this.FormBorderStyle = FormBorderStyle.None; this.MaximumSize = new Size(Screen.PrimaryScreen.Workin ...
- C#解决窗体全屏遮住任务栏
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea; 在初始话后添加这个即可实现,...............
- 【Android】Android 设置Activity窗体 不显示标题和全屏显示
[一]Android 设置Activity窗体 不显示标题 android:theme="@android:style/Theme.NoTitleBar" <activity ...
- winform 窗体最大化 分类: WinForm 2014-07-17 15:57 215人阅读 评论(0) 收藏
1:窗体首次加载时最大化 (1):主窗体 this.WindowState = FormWindowState.Maximized; //窗体显示中间部分,不显示窗体名称和最小化.最大化.关闭按钮 ...
- QT5中全屏显示子窗口和取消全屏的方法
问题描述:用QT5做了个MDI多窗体应用程序,想把子窗体全屏显示,用网上的方法,但总是遇到问题. 网上的解决方法原文在这:http://www.cnblogs.com/Rick-w/archive/2 ...
随机推荐
- nginx 引入外部文件
http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $ ...
- IM-即时通讯技术概述
IM-即时通讯技术概述 简述 即时通讯技术(IM)支持用户在线实时交谈.如果要发送一条信息,用户需要打开一个小窗口,以便让用户及其朋友在其中输入信息并让交谈双方都看到交谈的内容.大多数常用的即时通讯发 ...
- CreateThread与_beginthread, _beginthreadex创建线程的基本概念和区别(1)
这三个函数都可以创建新的线程,但都是如何创建的呢?当然MSDN文档最权威: Creates a thread to execute within the virtual address space o ...
- apache .htaccess文件详解和配置技巧总结
一..htaccess的基本作用 .htaccess是一个纯文本文件,它里面存放着Apache服务器配置相关的指令. .htaccess主要的作用有:URL重写.自定义错误页面.MIME类 ...
- 3644 - X-Plosives(水题,并差集)
3644 - X-Plosives A secret service developed a new kind of explosive that attain its volatile proper ...
- 小程序员在android移动应用上的赚钱经历
先说说我自己吧,二线城市(以外包为主)的小程序员,工作多年了,月收入5-6K.主要从事asp.net web网站开发,java,c++,php,ruby都懂一些,属于那种对问题不求甚解型,爱好电脑游戏 ...
- java String 怎么看里面有几个指定字符
我现在有一个String 字符串,我想看一下这个字符串里有几个指定的字符,比如指定字符是div求解 public class Main { public static void main(String ...
- Linux如何修改SSH端口号
SSH是什么? SSH 为 Secure Shell 由 IETF 的网络工作小组(Network Working Group)所制定: SSH 是建立在应用层和传输层基础上的一种安全协议. SSH传 ...
- Error creating bean with name 'org.springframework.validation.beanvalidation.LocalValidatorFactory
Error creating bean with name ‘org.springframework.validation.beanvalidation.LocalValidatorFactoryBe ...
- js Function 加不加new 详解
以下来自:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new The new operato ...