How to detect second screen control (plug in - plug out) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to detect second screen control (plug in - plug out)

qqallstarsqqallstars Posts: 1Member
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
if (Screen.AllScreens.Length > 1)
{

Form2 frm = new Form2();
frm.StartPosition = FormStartPosition.Manual;
Screen screen = GetSecondaryScreen();
frm.Location = screen.WorkingArea.Location;
frm.Size = new Size(screen.WorkingArea.Width, screen.WorkingArea.Height);
frm.Show();
}


}

public Screen GetSecondaryScreen()
{
if (Screen.AllScreens.Length == 1)
{
return null;
}
foreach (Screen screen in Screen.AllScreens)
{
if (screen.Primary == false)
{
return screen;
}
}
return null;
}


}
}



i got this codes .this is doing if second screen already pluged in form 2 opened at second screen.

but i want to like this i start to program at backround and if i plug in second monitor form 2 will open imadiatly when i plug out program still working at backgroung

and if i re plug in again open form 2 like this going . wont close program.



thank you for interesting...

Sign In or Register to comment.