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.
Showing a Windows form on a secondary monitor?
Try setting StartPosition parameter as FormStartPosition.Manual
inside your SetFormLocation
method.
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..!!");
}
Specifying startup window/form location on multiple displays
This should do the trick:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 f = new Form1();
f.StartPosition = FormStartPosition.Manual;
f.Location = Screen.PrimaryScreen.Bounds.Location;
Application.Run(f);
}
How to make the windows form open only on the main screen
You can try this:
/// <summary>
/// Sets the location of the form to primary screen.
/// </summary>
/// <param name="this">Instance of the form.</param>
/// <param name="x">The x coordinate of the form's location.</param>
/// <param name="y">The y coordinate of the form's location.</param>
public static void SetPrimaryLocation(this Form @this, int x = 0, int y = 0)
{
var rect = Screen.PrimaryScreen.WorkingArea;
@this.Location = new Point(rect.X + x, rect.Y + y);
}
Controlling output to a TV display while control panel is on laptop screen?
You can create two forms, one is the control panel with startup on the primary screen (default). For the other form, set the location to that of the secondary screen (i.e. TV or projector). To do this, iterate through i.e. Screen.AllScreens.Where(x=>!x.Primary).First(). The WorkingArea property gives the rectangle in which to place the second form.
Related Topics
Windows.Forms.Timer or System.Threading.Timer
Best Way to Display Decimal Without Trailing Zeroes
Convert Array of Bytes to Bitmapimage
How to Use Reflection to Call Method by Name
Are There Any Suggestions for Developing a C# Coding Standards/Best Practices Document
Why Are Private Fields Private to the Type, Not the Instance
How to Get Duplicate Items from a List Using Linq
How to Mock Static Methods in C# Using Moq Framework
Retrieve System Uptime Using C#
"Updatesourcetrigger=Propertychanged" Equivalent for a Windows Phone 7 Textbox
Routing: the Current Request for Action [...] Is Ambiguous Between the Following Action Methods
How to Split a String by Strings and Include the Delimiters Using .Net
How to Post a List of Items in MVC
What Are the Benefits of Using C# VS F# or F# VS C#
What .Net Collection Provides the Fastest Search
What Does |= (Single Pipe Equal) and &=(Single Ampersand Equal) Mean