0

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.

jLaw
  • 302
  • 3
  • 15
  • In what sense does it not working? – Ian Dec 27 '15 at 05:34
  • sometimes it is not fullscreen. it only occupy 3/4 of the screen. – jLaw Dec 27 '15 at 05:48
  • What is the screen size of your PC? And what is the screen size of the production PC? – Ian Dec 27 '15 at 05:55
  • production would be 1920 x 1080. and for my pc, I think its lower than that. – jLaw Dec 27 '15 at 05:56
  • And, does the size in the production PC follows the size in your PC? – Ian Dec 27 '15 at 05:58
  • yes, but again. it is sometimes fullscreen, sometimes not. – jLaw Dec 27 '15 at 06:00
  • I see... Although the production PC screen size is the same (always 1920 x 1080) and it is the same PC, it is sometimes fullscreen ans sometimes are not. Is this correct? – Ian Dec 27 '15 at 06:01
  • yes.. sometimes fullscreen and sometimes not. – jLaw Dec 27 '15 at 06:03
  • Likely, using WorkingArea is not safe to make full screen. As of why it is so with working area, perhaps it is the way its property working internally - may not be accessible for us to know apart from vague MSDN documentation https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.workingarea(v=vs.110).aspx – Ian Dec 27 '15 at 06:15

3 Answers3

1

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

Community
  • 1
  • 1
Ian
  • 30,182
  • 19
  • 69
  • 107
  • I already try that. if I do that, taskbar will not show. I think I should edit may question – jLaw Dec 27 '15 at 06:35
  • Edit my answer based on the new light of the question – Ian Dec 27 '15 at 06:58
  • you got some idea. But I can't test it for production yet. You just have to wait before I can mark it as an answer. Is it ok? Thank you – jLaw Dec 27 '15 at 07:06
  • That's ok... see if it works. We are here to help each other after all. ;) – Ian Dec 27 '15 at 07:11
0

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;
J3soon
  • 3,013
  • 2
  • 29
  • 49
0

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.

ehh
  • 3,412
  • 7
  • 43
  • 91