Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.