Link to home
Start Free TrialLog in
Avatar of neotechnology
neotechnology

asked on

Windows Forms: Full Screen on secondary display problem

Hi,

I've got some .NET windows forms which I am trying to display in full screen mode (i.e. takes up the entire display, start bar and all), yet I"m having difficulties getting it to display on the correct monitor.  

My code looks as per the code snippet attached.  As you can see, I've tried both setting both the Location and the Bounds properties of the form, both of which _appear_ to place the form in the correct position, i.e. its location property becomes 1024,0 in 1024x768 res.  However, when the form is rendered, it still appears on the primary screen.  If I switch the check in the GetSecondaryScreen method to return the primary screen, rather than the secondary, the result is exactly the same; it still fills up the monitor.
public FullScreenForm()
		{
			Screen displayScreen = GetSecondaryScreen();
			if (displayScreen != null)
			{
				// Properties needed for full screen-ness.
				this.MaximizeBox = false;
				this.MinimizeBox = false;
				//this.TopMost = true;
				this.FormBorderStyle = FormBorderStyle.None;
 
				// Place the window in the secondary screen
				this.Size = new System.Drawing.Size(displayScreen.WorkingArea.Width, displayScreen.WorkingArea.Right);
 
				//this.Location = screen.WorkingArea.Location;
				this.Bounds = new System.Drawing.Rectangle(
					displayScreen.WorkingArea.X, displayScreen.WorkingArea.Y, displayScreen.WorkingArea.Width, displayScreen.WorkingArea.Right);
 
			}
		}
 
		private Screen GetSecondaryScreen()
		{
			if (Screen.AllScreens.Length <= 1)
			{
				return null; 
			}
			foreach (Screen screen in Screen.AllScreens)
			{
				if (!screen.Primary)
				{
					return screen;
				}
			}
 
			return null;
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Darren
Darren
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neotechnology
neotechnology

ASKER

Thanks for that, solved my problem.  The hint was that I was trying to set the Location property in the constructor, which was being changed once I called Show() on the form.  I've since created a new method for showing, and set the Location in that before calling Show(), now it works fine.