DTI-Matt
DTI-Matt

Reputation: 2145

Form opens on wrong monitor

I have the following code:

//Create the login form.
ConnectionTypeForm ctf = new ConnectionTypeForm();
if (ctf.ShowDialog() == DialogResult.OK)
{
    Form form = Statics.CreateForm(
        "Main Form",
        new MainDesignerControl());
    Application.Run(form);
}

And when I run the program, the ConnectionTypeForm will open on my right (secondary) monitor, but as soon as the MainForm opens, it opens on the left hand side monitor (Primary). I can't set it's start position to FormStartPosition.CenterParent but as the ConnectionTypeForm isn't actually MainForm's parent, it's useless.

Any suggestions? I'd just like it to open on the same monitor.

Upvotes: 2

Views: 3950

Answers (3)

user117499
user117499

Reputation:

Specify the parent in ShowDialog() method and change the start position.

Dim ds As New FormDiagramSettings
ds.StartPosition = FormStartPosition.CenterParent
ds.ShowDialog(Me)

or c#

FormDiagramSettings ds = new FormDiagramSettings();
ds.StartPosition = FormStartPosition.CenterParent;
ds.ShowDialog(this);

Upvotes: 0

Carthorn
Carthorn

Reputation: 29

Its not a simple solution, but you can always store the position of the application in the registry. Each time you open the form, you can check to see if that value exists.

This way yourself or any users can change where the form opens up.

With some math you can figure out the "center" of the screen.

Also need to take into consideration if the resolution has changed (so your application is not off the screen, say if you un-dock a laptop and the resolution has changed).

Upvotes: 2

Ali Vojdanian
Ali Vojdanian

Reputation: 2111

Try this :

Form form = new Form();
        form.StartPosition = FormStartPosition.CenterParent;
        form.Show();

Upvotes: -1

Related Questions