CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2008
    Location
    .NET2.0 / .NET3.5 > VS2008
    Posts
    18

    [RESOLVED] Start Position

    My problem is that my form is not in the middle of the screen even though StartPosition is set to CenterScreen. Does anyone know why or how to fix us?

  2. #2
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: Start Position

    CenterScreen works for me in all applications I ever developed. Maybe you set not to CenterScreen but to CenterParent? That does not work. More I can not say without knowing your code.
    Useful or not? Rate my posting. Thanks.

  3. #3
    Join Date
    May 2008
    Location
    .NET2.0 / .NET3.5 > VS2008
    Posts
    18

    Re: Start Position

    Definately CenterScreen, was working then somewhere along the line. I have also tryed:
    [code]this.Location = new Point(((Screen.GetBounds(this).Width - this.Width)/2), ((Screen.GetBounds(this).Height - this.Height)/2));

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Start Position

    I suppose you're setting the property before you display the form, right?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    May 2008
    Location
    .NET2.0 / .NET3.5 > VS2008
    Posts
    18

    Re: Start Position

    It's okay I fixed it with this:
    Code:
    this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
    this.Location = new System.Drawing.Point(
    	((System.Windows.Forms.Screen.GetBounds(this).Width - this.ClientSize.Width) / 2),
    	((System.Windows.Forms.Screen.GetBounds(this).Height - this.ClientSize.Height) / 2)
    	);

  6. #6
    Join Date
    Mar 2010
    Posts
    2

    Unhappy Re: [RESOLVED] Start Position

    I have same problem... C# application with some wizard based forms... in properties I set start position to CenterScreen but it opens in upper left corner... not completely at 0,0 but in upper left.

    I tried the suggestion of adding the code to the function InitForm...no change.

    I looked at InitComponent and there is a line of code there also setting start position to Center Screen.

    ANy other suggestions?

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [RESOLVED] Start Position

    Pass the parent window to the child form before displaying.

  8. #8
    Join Date
    Mar 2010
    Posts
    2

    Re: [RESOLVED] Start Position

    How?

    Using VS 2008

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: [RESOLVED] Start Position

    Create a static method in the child form.

    Code:
    public  static  DialogResult ShowDlg( Form parent )
    {
      var dlg = new  Form2( ) { Owner = parent };
      return dlg.ShowDialog( );
    }


    In the Form2 properties, set the StartPosition property to CenterParent.

    In a button handler of Form1, call the static ShowDlg method and pass in the 'this' member.

    Code:
    private  void   button1_Click( object sender, EventArgs e )
    {
      if( DialogResult.OK == Form2.ShowDlg( this ) )
      {
    
        // do something here when the OK button has been clicked
      }
    }


    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured