欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#实现窗体全屏

程序员文章站 2022-06-21 11:03:50
方法一:适合WPF 方案二:适合Winform ......

方法一:适合wpf

//程序启动路径,与生成程序的exe文件在同一目录下
public string exepath = application.startuppath;
//定义窗体宽高
int screenwidth = 0;
int screenheight = 0;
screenwidth = (int)system.windows.systemparameters.primaryscreenwidth;
screenheight = (int)system.windows.systemparameters.primaryscreenheight;
// 设置全屏   
this.formborderstyle = formborderstyle.none;     //设置窗体为无边框样式
this.windowstate = formwindowstate.maximized;    //最大化窗体
this.left = 0;
this.top = 0;
this.width = screenwidth;
this.height = screenheight;
//窗体背景图
this.backgroundimage = image.fromfile(exepath + "文件名");

 

方案二:适合winform

//程序启动路径,与生成程序的exe文件在同一目录下
public string exepath = application.startuppath; //窗口左上角位置 public point m_formautographshowpos; //设置窗体尺寸 this.width = (int)system.windows.systemparameters.primaryscreenwidth; this.height = (int)system.windows.systemparameters.primaryscreenheight; this.clientsize = new system.drawing.size(width, height); //计算初始位置 m_formautographshowpos.x = 0; m_formautographshowpos.y = 0; location = m_formautographshowpos; //窗体背景图 this.backgroundimage = image.fromfile(exepath + "文件名");