Position of form question

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

When I use the Show() method to position a form, the runtime engine seems to
decide where to put it, normally just below and right of the parent window.
It does not seem to allow me to specify the co-ordinates in the Show(), and
it does not follow the Location property of the secondary form itself. I can
set the Location of the form after it is shown but then I see it painted in
the default location for a fraction of a second before it is moved.

How can I place it where I want it in a flicker-free way ?
 
This is precisely the question that I was looking an answer for. The
documentation says that you have to assign to the location using new
Point(x,y); I tried it but as soon as i show the form, it loses the
location. I have pasted the code below. The two WriteLine( ) calls, one
before show() nad one after show() write different things in the output
window. Surely somethings going wrong. I suspect it might be some design
time property of the form...

Any inputs on this?

TIA,

--Saurabh

--------code----------
Form2 f = new Form2();

int width = 280; //temp value hard coded

int height = 184; //temp value hard coded

//then position

Rectangle rect = Screen.PrimaryScreen.WorkingArea;

f.Location = new Point(rect.X + rect.Width - width - 15, rect.Y +
rect.Height - height - 15);

Console.WriteLine(f.Location.ToString());

f.Show();

Console.WriteLine(f.Location.ToString());

f.TopMost = true;

--------------------------end of code---------------
 
Set the StartPosition property to Manual. Then it should use the Location
when it's shown.

HTH
 
OK I managed to get it to do what I wanted, but I had to move the
positioning of the new form to the form itself, in the Load method.
Fortunately I could do this without having to pass it parameters.
 
* "JezB said:
When I use the Show() method to position a form, the runtime engine seems to
decide where to put it, normally just below and right of the parent window.
It does not seem to allow me to specify the co-ordinates in the Show(), and
it does not follow the Location property of the secondary form itself. I can
set the Location of the form after it is shown but then I see it painted in
the default location for a fraction of a second before it is moved.

Set the form's 'StartPosition' property to 'FormStartPosition.Manual'.
 
Hi JezB,

You should set
form.StartPosition = FormStartPosition.Manual;
And then the form will not disregard your location settings.
By default StartPosition is set to *WindowsDefaultLocation*
 
Back
Top