Showing a Windows form on a secondary monitor?
Try setting StartPosition parameter as FormStartPosition.Manual
inside your SetFormLocation
method.
Showing Winforms on dual-screen setup
Combining all answers here and in similar questions, the working solution for showing app on primary screen is this:
private void FormLogin_Load(object sender, EventArgs e)
{
this.Location = Screen.AllScreens[0].WorkingArea.Location;
ReallyCenterToScreen();
}
protected void ReallyCenterToScreen()
{
Screen screen = Screen.FromControl(this);
Rectangle workingArea = screen.WorkingArea;
this.Location = new Point()
{
X = Math.Max(workingArea.X, workingArea.X + (workingArea.Width - this.Width) / 2),
Y = Math.Max(workingArea.Y, workingArea.Y + (workingArea.Height - this.Height) / 2)
};
}
And to keep the MessageBoxes on the center screen is this:
MessageBox.Show(this, "Message")
Sources are the comment of @Bryce Wagner to my question, the answer from @Mohamad Shahrestani and from this question answer by @Sarsur.A
Window in fullscreen on second monitor
Going fullscreen on secondary monitor
using System.Linq;
using System.Windows;
namespace ExtendedControls
{
static public class WindowExt
{
// NB : Best to call this function from the windows Loaded event or after showing the window
// (otherwise window is just positioned to fill the secondary monitor rather than being maximised).
public static void MaximizeToSecondaryMonitor(this Window window)
{
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();
if (secondaryScreen != null)
{
if (!window.IsLoaded)
window.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
window.Left = workingArea.Left;
window.Top = workingArea.Top;
window.Width = workingArea.Width;
window.Height = workingArea.Height;
// If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
if ( window.IsLoaded )
window.WindowState = WindowState.Maximized;
}
}
}
}
How do I ensure a form displays on the additional monitor in a dual monitor scenario?
You need to use the Screen
class to find a screen that the original form is not on, then set the second form's Location
property based on that screen's Bounds
.
For example:
var myScreen = Screen.FromControl(originalForm);
var otherScreen = Screen.AllScreens.FirstOrDefault(s => !s.Equals(myScreen))
?? myScreen;
otherForm.Left = otherScreen.WorkingArea.Left + 120;
otherForm.Top = otherScreen.WorkingArea.Top + 120;
This will work for any number of screens.
Note that it is possible that the video card is configured so that Windows sees one large screen instead of two smaller ones, in which case this becomes much more difficult.
display window on secondary monitor
Ok, I've fixed the problem with remove the property WindowState="Maximized" in XAML code of MonitorWindow and changed the program as follows:
Queue<string> itemQueue = new Queue<string>();
MonitorWindow monitor = new MonitorWindow(itemQueue);
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();
if (secondaryScreen != null)
{
if (!monitor.IsLoaded)
monitor.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
monitor.Left = workingArea.Left;
monitor.Top = workingArea.Top;
monitor.Width = workingArea.Width;
monitor.Height = workingArea.Height;
// If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
monitor.Show();
if (monitor.IsLoaded)
monitor.WindowState = WindowState.Maximized;
}
Have Winform appear on all existing monitors at same time (Its an alert window)
This one worked perfectly for me..
First create an alert form with a label inside.
set the label1 property -> Modifier = public
void showMsgOnAllScreens(string msg)
{
for (int i = 0; i < Screen.AllScreens.Length; i++)
{
AlertForm alert = new AlertForm();
alert.label1.Text = msg;
alert.StartPosition = FormStartPosition.Manual;
alert.Location = new Point(
Screen.AllScreens[i].Bounds.Left + (Screen.AllScreens[i].Bounds.Width / 2 - alert.Width / 2),
Screen.AllScreens[i].Bounds.Height / 2 - alert.Height / 2);
alert.Show();
}
}
.
.
.
Now simply call the method to show msgs on all screens..
void button1_click (object sender, EventArgs e)
{
showMsgOnAllScreens("Warning.. Something's burning..!!");
}
Related Topics
Import and Export Excel - What Is the Best Library
Apply Properties Values from One Object to Another of the Same Type Automatically
Are Lambda Expressions in C# Closures
What Does "Datetime" Mean in C#
How to Check a Input Ip Fall in a Specific Ip Range
Advantages of Cache VS Session
Wpf: Binding a Contextmenu to an Mvvm Command
Fastest Method to Remove Empty Rows and Columns from Excel Files Using Interop
Multiple Parallel.Foreach Loops in .Net
Finding an Enum Value by Its Description Attribute
Xml Serialize Generic List of Serializable Objects
Escape Command Line Arguments in C#
How to Stop Backgroundworker Correctly
Why Should I Use Int Instead of a Byte or Short in C#
How to Determine a Mapped Drive's Actual Path
Log4Net: Programmatically Specify Multiple Loggers (With Multiple File Appenders)