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

2019-12-26 13:23:26王旭

易采站长站为您分析WinForm实现窗体最大化并遮盖任务栏的方法,涉及C#实现WinForm窗体全屏显示的实现及调用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了WinForm实现窗体最大化并遮盖任务栏的方法。。具体实现方法如下:

 

 
  1. using System;  using System.Windows.Forms; 
  2. using System.Drawing;  namespace CSImageFullScreenSlideShow 
  3. {  public class FullScreen 
  4. {  private FormWindowState winState; 
  5. private FormBorderStyle brdStyle;  private bool topMost; 
  6. private Rectangle bounds;  public FullScreen() 
  7. {  IsFullScreen = false; 
  8. }  public bool IsFullScreen 
  9. {  get; 
  10. set;  } 
  11. public void EnterFullScreen(Form targetForm)  { 
  12. if (!IsFullScreen)  { 
  13. Save(targetForm); // Save the original form state.  targetForm.WindowState = FormWindowState.Maximized; 
  14. targetForm.FormBorderStyle = FormBorderStyle.None;  targetForm.TopMost = true; 
  15. targetForm.Bounds = Screen.GetBounds(targetForm);  IsFullScreen = true; 
  16. }  } 
  17. /// <summary>  /// Save the current Window state. 
  18. /// </summary>  private void Save(Form targetForm) 
  19. {  winState = targetForm.WindowState; 
  20. brdStyle = targetForm.FormBorderStyle;  topMost = targetForm.TopMost; 
  21. bounds = targetForm.Bounds;  } 
  22. /// <summary>  /// Leave the full screen mode and restore the original window state. 
  23. /// </summary>  public void LeaveFullScreen(Form targetForm) 
  24. {  if (IsFullScreen) 
  25. {  // Restore the original Window state. 
  26. targetForm.WindowState = winState;  targetForm.FormBorderStyle = brdStyle; 
  27. targetForm.TopMost = topMost;  targetForm.Bounds = bounds;