jLaw
jLaw

Reputation: 302

fullscreen is not always functioning

Good day, I have a winform that can set full screen. But sometimes it's not. It is sometimes 3/4 of the screen but sometimes it is full screen. Below is my Code. Anybody knows why it's not always fullscreen....?

private void Form1_Load(object sender, EventArgs e)
{
    FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
    Width = Screen.PrimaryScreen.WorkingArea.Width;
    Height = Screen.PrimaryScreen.WorkingArea.Height;
}

When I run it in my pc. Its fine. But when it is in the production. I saw it did not go well. But sometimes it is ok.

By the way, I want my taskbar to be seen. If I set FormWindowState.Maximized, my taskbar would not be seen.

Thank you.

Upvotes: 0

Views: 162

Answers (3)

Ian
Ian

Reputation: 30813

The issue is that the WorkingArea is not the same with Full Screen. WorkingArea is relative, not the common way of forcing full screen.

There are a couple of ways to attempt to force the full screen.

One of the most popular way to force fill is by setting WindowsState to Maximized (also here and here - quite popular) combined with setting TopMost property to true.

private void Form1_Load(object sender, EventArgs e)
{
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

Alternatively, less popularly, you could also use Screen.Bounds (but may not be absolute too, try to put additional TopMost = true)

And finally, you could also using WorkingArea with conditional statement. To debug and see what is the WorkingArea size in you production PC, you could use GetWorkingArea method. This way, you can debug what is the working area in the production PC and if it is not full screen comparing to the size of the PC, you could force is to full screen. Not so efficient though...

Here is more explanation on working area vs screen area to help you making decisions.

Edit: with bar to be seen, what I could think of as another way to do this is by Get Screen Size. See:

How can I get the active screen dimensions?

Then you should limit the maximum dimension of your form (y/x-axis) such that you have room for your bar - that is, to be little less than the screen size in one of the axis. Then, on form load or other related events, you could control the position of your WinForm such that you won't block your bar.

See StartupPosition property:

C# window positioning

Upvotes: 1

ehh
ehh

Reputation: 3480

You just need to set the WindowState to Maximized at run-time:

WindowState = FormWindowState.Maximized;

Or at design-time, using the WindowState property of the form.

Upvotes: 0

J3soon
J3soon

Reputation: 3153

Screen.PrimaryScreen.WorkingArea only gets the screen's working area.

I think you need to change it to

Width = Screen.PrimaryScreen.Bounds.Width;
Height = Screen.PrimaryScreen.Bounds.Height;

Upvotes: 0

Related Questions