表格位置在表格开始时不正确

时间:2013-07-26 18:28:58

标签: c# winforms settings

为什么表单位置与设置位置不对应?

以下是代码:

[STAThread]
static void Main(string[] args)
{
//stuff (.....)
MyForm form = new MyForm ();
form.WindowState = Settings.Default.MainFormWindowState;
//When the form is shown, it location will be != of Settings.Default.MainFormLocation. Why?
//The idea is to change the form location before it is first shown.
form.Location = Settings.Default.MainFormLocation;
form.Size = Settings.Default.MainFormSize;

Application.Run(form);

1 个答案:

答案 0 :(得分:2)

确保将StartPosition设置为手动:

form.StartPosition = FormStartPosition.Manual;