Make this is as separate FullScreen.cs file
using System;
using System.Drawing;
using System.Windows.Forms;
namespace FullScreenMode
{
public class FullScreen
{
private Form _Form;
private FormWindowState _cWindowState;
private FormBorderStyle _cBorderStyle;
private Rectangle _cBounds;
private bool _FullScreen;
public FullScreen(Form form)
{
_Form = form;
_FullScreen = false;
}
private void ScreenMode()
{
// set full screen
if (!_FullScreen)
{
// Get the WinForm properties
_cBorderStyle = _Form.FormBorderStyle;
_cBounds = _Form.Bounds;
_cWindowState = _Form.WindowState;
// set to false to avoid site effect
_Form.Visible = false;
HandleTaskBar.hideTaskBar();
// set new properties
_Form.FormBorderStyle = FormBorderStyle.None;
_Form.WindowState = FormWindowState.Maximized;
_Form.Visible = true;
_FullScreen = true;
}
else // reset full screen
{
// reset the normal WinForm properties
// always set WinForm.Visible to false to avoid site effect
_Form.Visible = false;
_Form.WindowState = _cWindowState;
_Form.FormBorderStyle = _cBorderStyle;
_Form.Bounds = _cBounds;
HandleTaskBar.showTaskBar();
_Form.Visible = true;
// Not in full screen mode
_FullScreen = false;
}
}
public void ShowFullScreen()
{
ScreenMode();
}
public void ResetTaskBar()
{
HandleTaskBar.showTaskBar();
}
}
}
Use like Follow
from the form load or button click event call like
FullScreen fullScreen = new FullScreen(this);
fullScreen.ShowFullScreen();
No comments:
Post a Comment