WinForm实现窗体最大化并遮盖任务栏的方法
程序员文章站
2024-01-21 09:40:34
本文实例讲述了winform实现窗体最大化并遮盖任务栏的方法。分享给大家供大家参考。具体实现方法如下:
using system;
using system.w...
本文实例讲述了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#程序设计有所帮助。