Thursday, January 28, 2010

Understanding C#.net Border-less Form, when you maximize it

Hi There,
Have you ever created, a borderless window in C#.net?
There is problem with borderless window, if you maximize it, it goes FullScreen (over the taskbar).

Here is an analyis of how to achieve maximized borderless window.




If  you first set the border(anything other than FormBorderStyle.None) for the window and then set WindowState to maximize, You will get a standard maximized window, you can make it border-less there after.





private void btMaximize_Click(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedSingle;

if (this.WindowState != FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Maximized;
}
else
{
this.WindowState = FormWindowState.Normal;

}

this.FormBorderStyle = FormBorderStyle.None;
}





If you maximize a window after making it borderless it goes beyond the task-bar. You will get complete full-screen.



private void btFullscreen_Click(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
if (this.WindowState != FormWindowState.Maximized)
{

this.WindowState = FormWindowState.Maximized;
}
else
{
this.WindowState = FormWindowState.Normal;
}

}





No comments:

Post a Comment