C#实现窗体全屏

时间:2024-01-17 12:45:50

方法一:设置窗体属性

//程序启动路径,与生成程序的exe文件在同一目录下
public String exePath = Application.StartupPath;
//定义窗体宽高
int screenWidth = ;
int screenHeight = ;
screenWidth = (int)System.Windows.SystemParameters.PrimaryScreenWidth;
screenHeight = (int)System.Windows.SystemParameters.PrimaryScreenHeight;
// 设置全屏
this.FormBorderStyle = FormBorderStyle.None; //设置窗体为无边框样式
this.WindowState = FormWindowState.Maximized; //最大化窗体
this.Left = ;
this.Top = ;
this.Width = screenWidth;
this.Height = screenHeight;
//窗体背景图
this.BackgroundImage = Image.FromFile(exePath + "文件名");

方案二:设置窗体尺寸

//程序启动路径,与生成程序的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 = ;
m_formAutographShowPos.Y = ;
Location = m_formAutographShowPos;
//窗体背景图
this.BackgroundImage = Image.FromFile(exePath + "文件名");