2

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.

Erwin
  • 4,757
  • 3
  • 31
  • 41
DTI-Matt
  • 2,065
  • 9
  • 35
  • 60
  • 2
    Might be useful - http://stackoverflow.com/questions/2561104/how-do-i-ensure-a-form-displays-on-the-additional-monitor-in-a-dual-monitor-sc – Jason Evans Aug 28 '12 at 14:30
  • can't you just set `ConnectionTypeForm` as the parent for `MainForm`? – paul Aug 28 '12 at 14:34
  • 1
    Have you tried setting the position properties of the new form to the same as the ctf form? – MrFox Aug 28 '12 at 15:24
  • Look at this topic http://stackoverflow.com/questions/2561104/how-do-i-ensure-a-form-displays-on-the-additional-monitor-in-a-dual-monitor-sc – Alex Honcharuk Aug 30 '12 at 11:09

3 Answers3

2

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).

Carthorn
  • 19
  • 3
0

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);
-1

Try this :

Form form = new Form();
        form.StartPosition = FormStartPosition.CenterParent;
        form.Show();
Servy
  • 202,030
  • 26
  • 332
  • 449
Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47
  • 2
    OP specifically says he's tried this and it won't work because the form doesn't have a parent. – Servy Aug 28 '12 at 14:32