How do I find what screen the application is running on in C#

前端 未结 5 579
一生所求
一生所求 2020-12-11 06:05

How do I determine what screen my application is running on?

5条回答
  •  误落风尘
    2020-12-11 06:58

    This should get you started. Get a Button and a listbox on a Form and put this in the Button_Click:

    listBox1.Items.Clear();
    foreach (var screen in Screen.AllScreens)
    {
        listBox1.Items.Add(screen);
    }
    listBox1.SelectedItem = Screen.FromControl(this);            
    

    The answer is in the last line, remember that a Form is a Control too.

提交回复
热议问题