1

This is what I have so far, but it only opens on the primary monitor. My goal specifically is to open the file on the monitor associated with the button that I click.

    private void Form1_Load(object sender, EventArgs e)
    {
        Point btnTopLeft = new Point(15, 15);
        foreach (var screen in Screen.AllScreens)
        {
            Button btn = new Button();
            btn.Text = screen.DeviceName;
            btn.Size = new Size(100, 23);
            btn.Location = btnTopLeft;


            btn.Tag = screen;
            btn.Click += Btn_Click;

            this.Controls.Add(btn);
            btnTopLeft.Offset(0, btn.Height + 7);
        }
    }

    private void Btn_Click(object sender, EventArgs e)
    {
        if (sender == null || !(sender is Button))
            return;
        var btn = (Button)sender;

        if (btn.Tag == null || !(btn.Tag is Screen))
            return;
        var screen = (Screen)btn.Tag;

        System.Diagnostics.Process.Start("explorer.exe", @"c:\");

    }
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Chad
  • 11
  • 3
  • You want to "Open a file"? Or do you just mean open Explorer in a particular directory? – David P Oct 23 '15 at 12:02
  • 1
    Possible duplicate of [Launch an application and send it to second monitor?](http://stackoverflow.com/questions/3750113/launch-an-application-and-send-it-to-second-monitor) – Huntt Oct 23 '15 at 12:37

1 Answers1

0

Try using the Screen.GetBoundsmethod.

I believe this would give you which monitor your button mostly-is on https://msdn.microsoft.com/en-us/library/h6dba0zt%28v=vs.110%29.aspx

And this will give you which monitor a Rectangle is mostly-on https://msdn.microsoft.com/en-us/library/5z2btd02%28v=vs.110%29.aspx

You can also give it a Point, and it will return which monitor the point is on.

Once you figure out which monitor it is on, you could then use the Screen class again to get the bounds of the monitor and set your application's bounds to that.

Ex.

   this.Bounds = Screens.AllScreens[1].Bounds;

This is how I'd approach it first, though there may be a better way. Hope this helps.

jacobj
  • 21
  • 2