当前位置: 移动技术网 > IT编程>开发语言>c# > WinForm实现窗体最大化并遮盖任务栏的方法

WinForm实现窗体最大化并遮盖任务栏的方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网