FormStartPosition problem

  • Thread starter Thread starter Pohihihi
  • Start date Start date
P

Pohihihi

This one is really stupid Q but I am little not sure why my following code
is doing nothing in load event of form.
this.StartPosition = FormStartPosition.CenterScreen

Rather starting form in center it just opens as default (and that is where
ever)

any pointers?
 
This property can be set in the properties window. Note that, the properties
you set in the properties window does not appear anywhere apart from the
initialize components method which is called from the constructor. With this
in mind, you have to put you code in the constructor after the following line
of code:
InitializeComponent();
good luck!
Belee
 
Actually I should have said that it do work using properties but it do not
work if I try to set that at run time.
 
Where are you setting it "at runtime"? I would say that anywhere other than
the constructor would not work, since by that time the form has already
"started". You'd probably have to change forms Location property, instead
of StartPosition.
 
because in the load event, the StartPosition has already been read and form
initialized, so changing the StartPosition in form load has no effect.
 
my code is in Form load event. basically what I am doing is that loading
form state from registry. if there is no saved information then it will
default to center of the screen. It does work after Init function (as Belee
suggested) but i want it to function in load event. I can go for location
settings but StartPosition makes things way easy as I do not have to worry
about resolution/screen calculation on client machine.

adition to that what is the reason behind StartPosition not working in any
other place other than in ctor?

Thanks.
 
because in the load event, the StartPosition has already been read and form
initialized, so changing the StartPosition in form load has no effect.
 
Back
Top