简体   繁体   中英

How do I make my windows form full screen on both of my monitors(I have 2 monitors)?

In my code I putted this:

this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

and i want it to fill my other monitors.

"Maximized", by definition, means to fill a single monitor. If you maximize a window on a multi-monitor desktop, it will fill the monitor that contains the majority of the window's area. (The only way this would be different is if you had a video card/driver that combined all of your monitors into one giant monitor, so that the OS did not actually see separate monitors.)

There is, in general, no way to make a window fill all monitors. The reason is because the virtual screen may not be a perfect rectangle. The virtual screen is the rectangle created by the union of all monitors attached to the system. If those monitors are different sizes or shapes, or are arranged in an unusual way, you will end up with a non-rectangular virtual screen.

Consider the image in the above-linked document:

If I write the following code to make my window fill the entire virtual screen (or, actually, it would be the working area of the virtual screen, which is the area of the virtual screen that is not already filled by taskbars and other docked windows— ie , the area available for application windows):

Rectangle rcScreen = SystemInformation.VirtualScreen;

this.Location = New Point(rcScreen.Left, rcScreen.Top);
this.Size     = New Size(rcScreen.Width, rcScreen.Height);

I would end up with large pieces of my window invisible because they are on areas of the virtual screen that are not displayed on a monitor. So although this might work in your case, where you only have two monitors, it is not likely to work on other people's computers. Invisible windows are a really bad user experience.

If a user wants to resize your window to fill their entire virtual screen, then they can do that by the standard resizing functionality built into a window's border. There are user -focused utilities that facilitate management of windows on multi-monitor systems, but an application programmer should not make assumptions about the layout.

Filling the entire virtual screen with a borderless window only works for screensavers and other special effects, where it just doesn't matter that some portions of the window may be invisible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM