这篇文章主要为大家详细介绍了C#实现窗体全屏的两种方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文为大家分享了C#实现窗体全屏的具体代码,供大家参考,具体内容如下
方法一:不过此方法有时候会出现莫名的bug
//程序启动路径,与生成程序的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 + "文件名");
方法二:
//程序启动路径,与生成程序的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 + "文件名");
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:C#实现窗体全屏的两种方法
猜你喜欢
- c# 模拟线性回归的示例 2023-03-14
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- 如何使用C# 捕获进程输出 2023-03-10
- .NET CORE DI 依赖注入 2023-09-27
- Oracle中for循环的使用方法 2023-07-04
- Unity Shader实现模糊效果 2023-04-27
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- user32.dll 函数说明小结 2022-12-26
- Unity3D实现渐变颜色效果 2023-01-16