form placement: why won't this work?

  • Thread starter Thread starter Sergei Shelukhin
  • Start date Start date
S

Sergei Shelukhin

I have created a form that should op up as dialog; its components are
initialised the way it is done in standart forms that are created in design
mode, e.g. in InitialiseComponents function ( I copied the code from Form1
;) ).

But then, one bit doesn't seem to work - I placed it into the function and
the form is displayed somewhere else and not in the center of the screen.
Here's the code bit:

this.ClientSize = new System.Drawing.Size(200, 90); //this works, just to
show that I set size first and there shouldn't be any hidden errors with
undefined size
this.Location = new
System.Drawing.Point((Screen.PrimaryScreen.Bounds.Width -
this.ClientRectangle.Width)/2,(Screen.PrimaryScreen.Bounds.Height -
this.ClientRectangle.Height)/2);

What's wrong with it?
 
Back
Top