views:

696

answers:

1

I'm trying to set a Windows Form on secondary monitor, as follows:

    private void button1_Click(object sender, EventArgs e)
    {
        MatrixView n = new MatrixView();
        Screen[] screens = Screen.AllScreens;
        setFormLocation(n, screens[1]);
        n.Show();
    }

    private void setFormLocation(Form form, Screen screen)
    {
        // first method
        Rectangle bounds = screen.Bounds;
        form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);

        // second method
        //Point location = screen.Bounds.Location;
        //Size size = screen.Bounds.Size;

        //form.Left = location.X;
        //form.Top = location.Y;
        //form.Width = size.Width;
        //form.Height = size.Height;

    }

The properties of bounds seem correct, but in both methods I've tried, this maximizes the form on the primary monitor. Any ideas?

+3  A: 

Try setting WindowStartUpLocation parameter as "manual" inside your SetFormLocation method.

Sesh
Yeah, doing form.StartPosition = FormStartPosition.Manual; did the trick. Any idea why?
David Hodgson
@Henk No, it's Windows Forms. Here's a link to it: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.startposition(VS.80).aspx
David Hodgson
From MSDN: "Setting WindowStartupLocation to Manual causes a window to be positioned according to its Left and Top property values. If either the Left or Top properties aren't specified, their values are determined by Windows."http://msdn.microsoft.com/en-us/library/system.windows.window.windowstartuplocation.aspx
Sesh