WinForm实现窗体最大化并遮盖任务栏的方法
作者:我心依旧 时间:2022-09-19 20:00:19
本文实例讲述了WinForm实现窗体最大化并遮盖任务栏的方法。分享给大家供大家参考。具体实现方法如下:
using System;
using System.Windows.Forms;
using System.Drawing;
namespace CSImageFullScreenSlideShow
{
public class FullScreen
{
private FormWindowState winState;
private FormBorderStyle brdStyle;
private bool topMost;
private Rectangle bounds;
public FullScreen()
{
IsFullScreen = false;
}
public bool IsFullScreen
{
get;
set;
}
public void EnterFullScreen(Form targetForm)
{
if (!IsFullScreen)
{
Save(targetForm); // Save the original form state.
targetForm.WindowState = FormWindowState.Maximized;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.TopMost = true;
targetForm.Bounds = Screen.GetBounds(targetForm);
IsFullScreen = true;
}
}
/// <summary>
/// Save the current Window state.
/// </summary>
private void Save(Form targetForm)
{
winState = targetForm.WindowState;
brdStyle = targetForm.FormBorderStyle;
topMost = targetForm.TopMost;
bounds = targetForm.Bounds;
}
/// <summary>
/// Leave the full screen mode and restore the original window state.
/// </summary>
public void LeaveFullScreen(Form targetForm)
{
if (IsFullScreen)
{
// Restore the original Window state.
targetForm.WindowState = winState;
targetForm.FormBorderStyle = brdStyle;
targetForm.TopMost = topMost;
targetForm.Bounds = bounds;
IsFullScreen = false;
}
}
}
}
调用:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CSImageFullScreenSlideShow
{
public partial class Test : Form
{
public Test()
{
InitializeComponent();
}
private FullScreen fullScreen = new FullScreen();
private void button1_Click(object sender, EventArgs e)
{
if (fullScreen.IsFullScreen)
{
fullScreen.LeaveFullScreen(this);
}
else
{
fullScreen.EnterFullScreen(this);
}
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
标签:WinForm,窗体,最大化
0
投稿
猜你喜欢
Java 发送http请求上传文件功能实例
2021-07-04 22:30:53
Android BadTokenException异常解决案例详解
2022-04-08 16:10:59
mybatis框架xml下trim中的prefix与suffix等标签的用法
2023-09-20 18:55:24
SpringCloud实现灰度发布的方法步骤
2023-03-17 05:18:37
java新手入门——String类详解
2022-02-23 08:17:26
关于Maven的使用,这些你都真的了解么
2022-01-02 14:19:08
Android使用ViewPager实现类似laucher左右拖动效果
2022-05-18 20:33:59
Android利用Intent.ACTION_SEND进行分享
2023-07-10 05:02:18
详谈OnTouchListener与OnGestureListener的区别
2023-11-13 14:21:24
Java中MessageFormat的使用详解
2022-03-14 02:01:02
java中Executor,ExecutorService,ThreadPoolExecutor详解
2023-10-31 10:50:56
Android自定义View实现微信语音界面
2022-03-27 20:35:27
利用 filter 机制给静态资源 url 加上时间戳,来防止js和css文件的缓存问题
2022-03-16 07:51:24
Spring AOP与AspectJ的对比及应用详解
2022-07-07 12:50:47
JAVA基于SnakeYAML实现解析与序列化YAML
2023-11-26 06:14:44
在Spring Boot中使用Spring-data-jpa实现分页查询
2023-12-03 21:35:39
WinForm实现的图片拖拽与缩放功能示例
2021-06-18 09:17:26
SWT(JFace)体验之打开多个Form
2021-11-29 03:19:15
详解Java内存泄露的示例代码
2023-06-08 03:34:51
Java用栈实现综合计算器
2021-08-16 02:01:36