首页 > 编程 > C# > 正文

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

2019-10-29 21:38:42
字体:
来源:转载
供稿:网友

这篇文章主要介绍了WinForm实现窗体最大化并遮盖任务栏的方法,涉及C#实现WinForm窗体全屏显示的实现及调用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

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

 

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

调用:

 

 
  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.ComponentModel; 
  4. using System.Data; 
  5. using System.Drawing; 
  6. using System.Text; 
  7. using System.Windows.Forms; 
  8. namespace CSImageFullScreenSlideShow 
  9. public partial class Test : Form 
  10. public Test() 
  11. InitializeComponent(); 
  12. private FullScreen fullScreen = new FullScreen(); 
  13. private void button1_Click(object sender, EventArgs e) 
  14. if (fullScreen.IsFullScreen) 
  15. fullScreen.LeaveFullScreen(this); 
  16. else 
  17. fullScreen.EnterFullScreen(this); 

希望本文所述对大家的C#程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表