Size and location change

  • Thread starter Thread starter PiotrKolodziej
  • Start date Start date
P

PiotrKolodziej

Hi
This is my simple code:

public Form1()

{

this.Size = configFile.getSize();

this.Location = configFile.getLocation(this.Size.Width);

this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form1_Closing);

InitializeComponent();

}

When the size and location is set, everything is ok.
But after InitializeComponent() they are set to the default values - ones
that i have set in properties window.

Why this happens and where should i set new values.


Thx
 
Hi,

InitializeComponent sets the size and location specified in the Design
window of Visual Studio.
If you want to modify this in code, put your code AFTER InitializeComponent
 
If you use the constructor add all your code after InitializeComonent method
call. Other alternatice is to move your code in OnLoad.
 
public Form1()

{

this.Size = configFile.getSize();

this.Location = configFile.getLocation(this.Size.Width);

this.Closing += new
System.ComponentModel.CancelEventHandler(this.Form1_Closing);

InitializeComponent();

}

When the size and location is set, everything is ok.
But after InitializeComponent() they are set to the default values - ones
that i have set in properties window.

Why this happens and where should i set new values.

In the designer, set the StartPosition propery to Manual. Then in your
constructor, set the size and location of your form *after* the
InitializeComponent() call (actually, there is a very clear comment in the
auto-generated constructor that instructs you to do that).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top