using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace testscreen
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(92, 44);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1
//
this.listBox1.Location = new System.Drawing.Point(76, 136);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(544, 95);
this.listBox1.TabIndex = 1;
//
// button2
//
this.button2.Location = new System.Drawing.Point(228, 44);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(372, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(260, 68);
this.label1.TabIndex = 3;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(668, 262);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Locationchanged += new System.EventHandler(this.Form1_Locationchanged);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
int index;
int upperBound;
// Gets an array of all the screens connected to the system.
Screen [] screens = Screen.AllScreens;
upperBound = screens.GetUpperBound(0);
for(index = 0; index <= upperBound; index++)
{
// For each screen, add the screen properties to a list box.
listBox1.Items.Add("Device Name: " + screens[index].DeviceName);
listBox1.Items.Add("Bounds: " + screens[index].Bounds.ToString());
listBox1.Items.Add("Type: " + screens[index].GetType().ToString());
listBox1.Items.Add("Working Area: " + screens[index].WorkingArea.ToString());
listBox1.Items.Add("Primary Screen: " + screens[index].Primary.ToString());
}
}
private void button2_Click(object sender, System.EventArgs e)
{
int index;
int upperBound;
Screen[] screens = Screen.AllScreens;
if (screens.Length == 2)
{
Point pt = new Point(1281,0);
if (Screen.FromControl(this).DeviceName == @"\\.\DISPLAY1")
return;
Form myform = new Form2();
// myform.StartPosition = pt; //.DesktopLocation = pt;
myform.Show();
}
}
private void Form1_Locationchanged(object sender, System.EventArgs e)
{
Screen[] screens = Screen.AllScreens;
label1.Text = "There are "+screens.Length+" displays";
label1.Text += "\n" + Screen.FromControl(this).DeviceName;
}
}
}
This is just a sample app for me to learn how to do this. I have read that with 2 monitors running a 1280x1024, I should be able to open the window at (1281,0) and it would be on the second display. But, I don't know how to specify that as the top left corner of its window when I open 'form2' (myform in the program above).
Thanks for any suggestions.

New Topic/Question
Reply




MultiQuote




|