C#窗体全屏功能
最近有朋友让我给他弄个应用程序全屏的功能,例如银行的取号程序界面。所以我从网上查询了一些实现的方法。
C#应用程序中如何实现全屏幕显示功能?
效果就像windows自带的屏幕保护程序和众多的游戏那样,无论是否设置了“将任务栏保持在其他窗口的前端”都不显示任务栏
实现方式一
在网上找来一些简单的实现方式:
this.FormBorderStyle = FormBorderStyle.None; //设置窗体为无边框样式
this.WindowState = FormWindowState.Maximized; //最大化窗体
然后再设置窗体的位置和大小,例如:Width=1024 Height=768 Left=0 Top=0等size的值
把以上两句代码直接放到Form1_Load的方法中,就可以了,比较简单,我就不贴代码了。
参考出处:http://blog.csdn.net/friendan/article/details/7350570
============================================================
实现方式二
调用系统的API函数,如user32.dll中的FindWindow和ShowWindow函数,具体代码如下:
[DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern Int32 ShowWindow(Int32 hwnd, Int32 nCmdShow);
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern Int32 FindWindow(string lpClassName, string lpWindowName);
代码如下:
using System;
using System.Windows.Forms; using System.Drawing;
using System.Runtime.InteropServices; namespace FullScr
{
public partial class Form1 : Form
{ Boolean m_IsFullScreen = false;//标记是否全屏 public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} /// <summary>
/// 全屏按钮的Click事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
m_IsFullScreen = !m_IsFullScreen;//点一次全屏,再点还原。
this.SuspendLayout();
if (m_IsFullScreen)//全屏 ,按特定的顺序执行
{
SetFormFullScreen(m_IsFullScreen);
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
this.Activate();//
}
else//还原,按特定的顺序执行——窗体状态,窗体边框,设置任务栏和工作区域
{
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = FormBorderStyle.Sizable;
SetFormFullScreen(m_IsFullScreen);
this.Activate();
}
this.ResumeLayout(false);
} /// <summary>
/// 设置全屏或这取消全屏
/// </summary>
/// <param name="fullscreen">true:全屏 false:恢复</param>
/// <param name="rectOld">设置的时候,此参数返回原始尺寸,恢复时用此参数设置恢复</param>
/// <returns>设置结果</returns>
public Boolean SetFormFullScreen(Boolean fullscreen)//, ref Rectangle rectOld
{
Rectangle rectOld = Rectangle.Empty;
Int32 hwnd = ;
hwnd = FindWindow("Shell_TrayWnd", null);//获取任务栏的句柄 if (hwnd == ) return false; if (fullscreen)//全屏
{
ShowWindow(hwnd, SW_HIDE);//隐藏任务栏 SystemParametersInfo(SPI_GETWORKAREA, , ref rectOld, SPIF_UPDATEINIFILE);//get屏幕范围
Rectangle rectFull = Screen.PrimaryScreen.Bounds;//全屏范围
SystemParametersInfo(SPI_SETWORKAREA, , ref rectFull, SPIF_UPDATEINIFILE);//窗体全屏幕显示
}
else//还原
{
ShowWindow(hwnd, SW_SHOW);//显示任务栏
SystemParametersInfo(SPI_SETWORKAREA, , ref rectOld, SPIF_UPDATEINIFILE);//窗体还原
}
return true;
} #region user32.dll public const Int32 SPIF_UPDATEINIFILE = 0x1;
public const Int32 SPI_SETWORKAREA = ;
public const Int32 SPI_GETWORKAREA = ;
public const Int32 SW_SHOW = ;
public const Int32 SW_HIDE = ; [DllImport("user32.dll", EntryPoint = "ShowWindow")]
public static extern Int32 ShowWindow(Int32 hwnd, Int32 nCmdShow); [DllImport("user32.dll", EntryPoint = "FindWindow")]
private static extern Int32 FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, ref Rectangle lpvParam, Int32 fuWinIni); #endregion }
}
参考出处:http://www.cnblogs.com/ArcScofield/archive/2013/01/02/Form_Fullscreen.html
实现方式三
窗体最大化,不占用任务栏,具体实现如下:
this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea; //设置最大化的大小为工作区域
this.WindowState = FormWindowState.Maximized;
出处:https://blog.csdn.net/lwjzjw/article/details/80828353
C#窗体全屏功能的更多相关文章
- js 实现操作浏览器或者元素的全屏与退出全屏功能
<!DOCTYPE html> <html lang="en" id="div1"> <head> <meta cha ...
- Chrome71版本使用screenfull.js全屏功能时报参数错误
在生产环境长期使用的一个“全屏”功能突然失效了,查看Console 如下报错: Failed to execute 'requestFullscreen' on 'Element': paramete ...
- 富文本编辑器vue2-editor实现全屏功能
vue2-editor非常不错,可惜并未带全屏功能,自己实现了一个,供大家参考. 实现思路:自定义模块. 1. 定义全屏模块Fullscreen /** * 编辑器的全屏实现 */ import no ...
- JS实现元素的全屏、退出全屏功能
在实际开发中,我们很可能需要实现某一元素的全屏和退出全屏功能,如canvas.所幸的是,js提供了相关api用来处理这一问题,只需简单的调用requestFullScreen.exitFullScr ...
- C#实现窗体全屏
方法一:设置窗体属性 //程序启动路径,与生成程序的exe文件在同一目录下 public String exePath = Application.StartupPath; //定义窗体宽高 ; ; ...
- iOS 视频全屏功能 学习
项目中,也写过类似"视频全屏"的功能, 前一阵子读到今日头条 的一篇技术文章,详细介绍三种旋转方法差异优劣最终择取.文章从技术角度看写的非常好,从用户角度看,也用过多家有视频功能的 ...
- Delphi7 实现窗体全屏方法
设置要全屏的窗体的ALign 属性为ALcLient ,此法最快.当然对我来说,我并不知道这个,所以走了远路,等后来在实现窗体禁止移动的时候才想到了这里,汗.注意:这种全屏方式不会挡了系统的任务栏.. ...
- vitamio videoView 用隐藏除videoview的控件,并旋转屏幕方向实现的全屏功能,出现的画面不能填充满videoview(画面不完整)
使用vitamio 封装的播放器 当切换到全屏模式,有时候会出现播放的画面不是全屏的情况, 全屏时,画面只占左半部分并出现拉伸效果,还显示不全,等等其他情况 阅读分析源代码发现是getHolder() ...
- winform窗体全屏
bool fullscreen = false;Rectangle rect = new Rectangle();private void button4_Click(object sender, E ...
随机推荐
- [Notes] Reading Notes on [Adaptive Robot Control – mxautomation J. Braumann 2015]
Reading sources: 1.Johannes Braumann, Sigrid Brell-Cokcan, Adaptive Robot Control (ARC ) Note: buil ...
- dropbear
生成ssh连接所需要的公钥,如下: /usr/bin/dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key (dss加密,长度默认 ...
- mui学习笔记
一.页面刷新问题 1.父页面A跳转到子页面B,B页面修改数据后再跳回A页面,刷新A页面数据 (1).父页面A代码 window.addEventListener("pageflowrefre ...
- [php-src]理解Php内核中的函数与INI
内容均以php-5.6.14为例. 一. 函数结构 内核中定义一个php函数使用 PHP_FUNCTION 宏 包装,扩展也不例外,该宏在 ./main/php.h:343 有着一系列类似以 PHP ...
- Ubuntu10.0.4安装NDK
android版本遇到.so文件crash,需要使用ndk来定位报错代码. 从这里下载ndk安装文件: http://www.androiddevtools.cn/ 运行 ./android-ndk- ...
- hdoj 2544最短路
Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要 ...
- [Chapter 3 Process]Practice 3.5 When a process creates a new process using the fork() operation
3.5 When a process creates a new process using the fork() operation, which of the following state is ...
- 【温故Delphi】之编译与链接(转)
本文基本转自“Delphi编译/链接过程” @瓢虫Monster,向瓢虫君学习,:) 下图展示了Delphi是怎样编译源文件,并把它们链接起来,最终形成可执行文件的. 当Delphi编译项目(Proj ...
- C# 基础(3)
跳转语句 Goto(现在一般不使用) 标志位 Flag true false 常量:(不可改变的量) 语法: Const 类型 变量名 = 常量值 在定义时赋值,其他地方不能赋值 枚举 是自己定义了一 ...
- 配置org.springframework.scheduling.quartz.CronTriggerBean(转)
注意:定时器方法里如果执行动作的时间超出了定时器的周期,将会产生两个方法同时执行的情况. 一个Quartz的CronTrigger表达式分为七项子表达式,其中每一项以空格隔开,从左到右分别是:秒,分, ...