/// <summary> /// Create a form for application containing UcMultiSyncMain. /// And this form can remember its own location in multiscreen. /// </summary> /// <returns></returns> public static Form CreateMainForm(SyncSettingsBase settings) { if (settings == null) { throw new ArgumentNullException("settings", "How could settings be null?"); } CommonForm form = new CommonForm(); form.ShowInTaskbar = true; // form.AutoSize = true;/// Because this form is used as main form. // AutoSize can not work properly probably the autosize takes effects // before UcMultiSyncMain is loaded. // form.AutoSizeMode = AutoSizeMode.GrowAndShrink; form.Icon = Properties.Resources.syncIcon; form.Load += delegate(object sender, EventArgs e) { try { UcMultiSyncMain uc = new UcMultiSyncMain(settings); form.AddControl(uc, ProgramSettings.Default.ProductName); // form.AutoSize = true;//not working either } catch (System.Configuration.ConfigurationErrorsException exception) { MessageBox.Show("Configuration has problem: " + e.ToString() + "~" + exception.Message); } }; MultiScreenHelper.RefineLocation(form, ProgramSettings.Default.Location, ProgramSettings.Default.ScreenDeviceName); form.FormClosing += delegate(object sender, System.Windows.Forms.FormClosingEventArgs e) { ProgramSettings.Default.Location = form.Location; ProgramSettings.Default.ScreenDeviceName = System.Windows.Forms.Screen.FromControl(form).DeviceName; ProgramSettings.Default.Save(); }; return(form); }