Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Launch Application Windows in MultiScreen

0.00/5 (No votes)
13 Sep 2010 1  
Launch Application Forms in MultiScreen

Introduction

This has been an ongoing topic for a while and I keep on getting question(s) on how can we launch Windows or in our case application(s) in different screens. In the place that I currently work, City of Dreams, we have many different types of adapters for many A/V systems and the applications like Lucky Draw, Slot Results, etc. have to be automatically launched on the correct AV to have effects like Animation(s) on one type, random numbers on other, etc.

Launcher

MultiScreen01.JPG

Launched

MultiScreen02.JPG

The AllScreens

This is all it takes to get the information of all the screens currently hosted in the system System.Windows.Forms.Screen.

So to populate our dropdown; loop through the:

Screen[] scr = Screen.AllScreens
this.cmbDevices.Items.Clear();
foreach (System.Windows.Forms.Screen s in scr)
{
    strDeviceName = s.DeviceName.Replace("\\\\.\\", "");
    this.cmbDevices.Items.Add(strDeviceName);
    // you can check the device is primary or not this way
    if (s.Primary) this.cmbDevices.Items.Add(">" + strDeviceName);
    else this.cmbDevices.Items.Add(strDeviceName);
}
this.cmbDevices.SelectedIndex = 0;

Launch

There are only two properties that have to be set correctly in order to ensure it is properly launched into the correct display. Form.StartPosition & Form.Location.

Screen[] scr = Screen.AllScreens
Form oForm = new Form()
oForm.Left = scr[0].Bounds.Width;
oForm.Top = scr[0].Bounds.Height;
oForm.StartPosition = FormStartPosition.Manual;
oForm.Location = scr[0].Bounds.Location;
        oForm.Show();

Putting It All Together

Here we go, this is all it takes to launch your forms into user selected display.

public partial class frmMain : Form
{
    Form[] aryForms = new Form[5];                      // Allow 5 total forms.
    int currentPointer = 0;                             //
    Screen[] scr = Screen.AllScreens;
    
    public frmMain()
    {
        InitializeComponent();
        LoadScreen();
    }
    
    private void LoadScreen()
    {
        String strDeviceName = String.Empty;
        
        this.cmbDevices.Items.Clear();
        foreach (Screen s in scr)
        {
            strDeviceName = s.DeviceName.Replace("\\\\.\\", "");
            this.cmbDevices.Items.Add(strDeviceName);
            /* Enable this section, if you want to point to 
	   user this is the default screen.
            if (s.Primary) this.cmbDevices.Items.Add(">" + strDeviceName);
            else this.cmbDevices.Items.Add(strDeviceName);
            */
        }
        this.cmbDevices.SelectedIndex = 0;
    }
    
    private void btnLaunchIn_Click(object sender, EventArgs e)
    {
        int intLaunchScreen = getScreenNumber(this.cmbDevices.SelectedItem.ToString());
        
        if (currentPointer <= 4)
        {
            aryForms[currentPointer] = new frmLaunchedWindow();
            aryForms[currentPointer].Text = 
		aryForms[currentPointer].Text + currentPointer;
            aryForms[currentPointer].Left = scr[intLaunchScreen].Bounds.Width;
            aryForms[currentPointer].Top = scr[intLaunchScreen].Bounds.Height;
            aryForms[currentPointer].StartPosition = FormStartPosition.Manual;
            aryForms[currentPointer].Location = scr[intLaunchScreen].Bounds.Location;
            //Point p = new Point(scr[0].Bounds.Location.X, scr[0].Bounds.Location.Y);
            //aryForms[currentPointer].Location = p;
            aryForms[currentPointer].Show();
            currentPointer += 1;
        }
    }
    private int getScreenNumber(String DeviceID)
    {
        int i = 0;
        foreach (Screen s in scr)
        {
            if (s.DeviceName == "\\\\.\\"+DeviceID) return i;
            i += 1;
        }
        // if cannot find the device reset to the default 0
        return 0;
    }
}

History

  • 13th September, 2010: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here