Full Screen?

A

Ana Lindt

Hi all,

How do I make my windows form full screen? (C#) I actualy dont need to hide
the window elements such as the border, title bar or even the
maximize/minimize boxes but i do need to either place my window on top of
the task bar or hide the latest.

Thanks for any help.

Regards,

Ana L.
 
M

Mikael Gustavsson

Hi Ana!

There may be other ways of doing this, I dont know of any other however.

In the properties for the form choose the property

FromBorderStyle None

Now the window will have no maximize/minimize/close boxes.

Maximize the window for instance in the constructor.

public Form1()
{
this.WindowState = FormWindowState.Maximized;
InitializeComponent();
}

Now the window will cover the entire screen, including the taskbar

Good luck!

//Mikael
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Ana,

This question was asked before. The solution that usually is given is to
make your form bordless, without caption, etc. Yes, this works, but this is
not the only way to make the form coverring the taskbar.
You can have a form full screen event if it has thick border and caption.
The conditions that your form has to meet are:
1. to be maximized
2. the client rectangle to be big enough to cover the entire screen. Pay
attention on the requirement that the CLIENT RECT has to be that big.
That means the caption and the WindowsForm's menu and status bar have to be
off the screen. However, if you use third party menu and status bar controls
they are usually implemented as normal controls hosted in the form's client
area and they can be visible.

If you meet those requirements Windows will hide the taskbar for you.

For more info read this KB in MSDN
ms-help://MS.MSDNQTR.2003FEB.1033/enu_kbwin32sdk/en-us/win32sdk/Q179363.htm

In Win32 to make the form that big you have to handle WM_GETMINMAX info
messages. Form class handles
that message for you and provide properties MaximumSize and MaximizedBounds
that can be used. Note: Both have to be set in order to be able to cover the
taskbar

The problem is how to calculate the bounding rectangle of the Form in a way
to accommodate client rectangle as big as the screen. I haven't found method
that returns that info so I'll give you one idea how to calculate it
yourself. BTW there is a method you can use to set the size of the client
rectangle and it will calculate the bounding rectangle for you but I can't
see any way to use it for the case.

So here is my solution. Copy and paste this method in your form class. Run
the application and maximize the form it has to cover the entire screen.
Perhaps it is not the best way to do the calculation. Because if the menu
wraps at the moment of calculation the result will be far from perfect. The
other solution could be to use PInvoke and call AdjustWindowRectEx or
AdjustWindowRect API.
If you or any one in the group has better solution for this calculation it
would be really helpful if make a post

However here is the code.

protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);

Point clientTL = this.PointToScreen(new Point(ClientRectangle.X,
ClientRectangle.Y));
Point clientBR = this.PointToScreen(new Point(ClientRectangle.X +
ClientRectangle.Width, ClientRectangle.Y + ClientRectangle.Height));
Point frameTL = this.Location;
Point frameBR = new Point(this.Location.X + this.Width, this.Location.Y +
this.Height);

int topXDelta = clientTL.X - frameTL.X;
int topYDelta = clientTL.Y - frameTL.Y;
int bottomXDelta = frameBR.X - clientBR.X;
int bottomYDelta = frameBR.Y - clientBR.Y;

Rectangle newFrameBounds = Screen.GetBounds(this);
newFrameBounds.Inflate(topXDelta + bottomXDelta, topYDelta +
bottomYDelta);
newFrameBounds.Location = new Point(-topXDelta, -topYDelta);

this.MaximumSize = newFrameBounds.Size;
this.MaximizedBounds = newFrameBounds;
}
 
A

Ana Lindt

Hi and thank you for such a detailed reply.

I'm trying to work with your solution. So far i'm stuck with a stack
overflow at:

"Point clientTL = this.PointToScreen(new Point(ClientRectangle.X,
ClientRectangle.Y));"

Regards,

Ana L.
 
A

Ana Lindt

Ok i fixed the problem, it was my bad.
Everything is working perfectly now, this is exactly what I needed.
Actualy my form doesn't have menu or status bars, I wanted it to
look like powerpoint's fullscreen mode so the results are just as expected.

Again, thank you and regards,

Ana L.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top