Proven and easy solution
I searched for the answer to this question in SO and some other sites, but one gave an answer, it was very difficult for me, and some other answers just didn’t work correctly, so after a lot of testing the code, I solved this puzzle.
Note. I am using Windows 8 and my taskbar is not in auto-hide mode.
I found that setting WindowState to Normal before making any changes will stop the error with the taskbar closed.
The code
I created this class, which has two methods, the first goes into "full screen mode" and the second leaves "full screen mode". Thus, you just need to create an object of this class and pass the form you want to set full screen as an argument to EnterFullScreenMode or LeaveFullScreenMode:
class FullScreen { public void EnterFullScreenMode(Form targetForm) { targetForm.WindowState = FormWindowState.Normal; targetForm.FormBorderStyle = FormBorderStyle.None; targetForm.WindowState = FormWindowState.Maximized; } public void LeaveFullScreenMode(Form targetForm) { targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; targetForm.WindowState = FormWindowState.Normal; } }
Usage example
private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e) { FullScreen fullScreen = new FullScreen(); if (fullScreenMode == FullScreenMode.No)
I put the same answer to another question, which I'm not sure if this is a duplicate or not. (Link to another question: How to display a Windows form in full screen on the taskbar? )
Zignd May 26 '13 at 22:59 2013-05-26 22:59
source share