public static void SaveListControlSelectedIndex(string AppProductName, ContainerControl FrmOrUc, ListControl lst, CXmlConfig xc) { string FrmOrUcName = FrmOrUc.Name; string Section = AppProductName + "\\" + FrmOrUcName; string ControlName = lst.Name; if (xc != null) { xc.SaveSetting(FrmOrUcName + "." + ControlName, lst.SelectedIndex); } else { CRegistry.SaveSetting(Section, ControlName, lst.SelectedIndex); } }
/// <summary> /// Form의 위치와 크기 정보를 다음에 불러올 수 있도록 레지스트리에 저장함. /// </summary> /// <param name="AppProductName">Application.ProductName</param> /// <param name="FrmOrUc">Form 개체</param> /// <param name="Kind">저장될 값의 종류</param> /// <example> /// 다음은 폼이 닫힐 때 폼의 위치, 크기 정보를 저장하고, /// 폼이 열릴 때 저장되었던 폼의 위치, 크기 정보를 불러와서 열린 폼에 적용합니다. /// <code> /// private void Form1_Load(object sender, System.EventArgs e) /// { /// CWinForm.RestoreFormStatus(Application.ProductName, this, FormSaveRestoreKind.SizePosition); /// } /// private void Form1_FormClosing(object sender, FormClosingEventArgs e) /// { /// CWinForm.SaveFormStatus(Application.ProductName, this, FormSaveRestoreKind.SizePosition); /// } /// </code> /// </example> public static void SaveFormStatus(string AppProductName, ContainerControl FrmOrUc, FormSaveRestoreKind Kind, CXmlConfig xc) { string FrmOrUcName = FrmOrUc.Name; string Section = AppProductName + "\\" + FrmOrUcName; if ((Kind & FormSaveRestoreKind.SizePosition) == FormSaveRestoreKind.SizePosition) { Form frm = (Form)FrmOrUc; if (xc != null) { xc.SaveSetting(FrmOrUcName + ".WindowState", Convert.ToInt32(frm.WindowState)); } else { CRegistry.SaveSetting(Section, "WindowState", Convert.ToInt32(frm.WindowState)); } if (frm.WindowState == FormWindowState.Normal) { if (xc != null) { xc.SaveSetting(FrmOrUcName + ".Left", frm.Left); xc.SaveSetting(FrmOrUcName + ".Top", frm.Top); } else { CRegistry.SaveSetting(Section, "Left", frm.Left); CRegistry.SaveSetting(Section, "Top", frm.Top); } switch (frm.FormBorderStyle) { case FormBorderStyle.Fixed3D: case FormBorderStyle.FixedDialog: case FormBorderStyle.FixedSingle: case FormBorderStyle.FixedToolWindow: break; default: if (xc != null) { xc.SaveSetting(FrmOrUcName + ".Width", frm.Width); xc.SaveSetting(FrmOrUcName + ".Height", frm.Height); } else { CRegistry.SaveSetting(Section, "Width", frm.Width); CRegistry.SaveSetting(Section, "Height", frm.Height); } break; } } } if (((Kind & FormSaveRestoreKind.TextBox) == FormSaveRestoreKind.TextBox) || ((Kind & FormSaveRestoreKind.NumericUpDown) == FormSaveRestoreKind.NumericUpDown) || ((Kind & FormSaveRestoreKind.ListControl) == FormSaveRestoreKind.ListControl) || ((Kind & FormSaveRestoreKind.CheckBox) == FormSaveRestoreKind.CheckBox)) { List <Control> aCtl = new List <Control>(); aCtl = GetControls(FrmOrUc, ref aCtl); foreach (Control ctl in aCtl) { Type TypeCur = ctl.GetType(); string ControlName = ctl.Name; if (((Kind & FormSaveRestoreKind.TextBox) == FormSaveRestoreKind.TextBox) && (TypeCur.BaseType == typeof(TextBoxBase))) { TextBoxBase txt = (TextBoxBase)ctl; if (xc != null) { xc.SaveSetting(FrmOrUcName + "." + ControlName, txt.Text); } else { CRegistry.SaveSetting(Section, ControlName, txt.Text); } } else if (((Kind & FormSaveRestoreKind.NumericUpDown) == FormSaveRestoreKind.NumericUpDown) && (TypeCur == typeof(NumericUpDown))) { NumericUpDown nud = (NumericUpDown)ctl; if (xc != null) { xc.SaveSetting(FrmOrUcName + "." + ControlName, nud.Value); } else { CRegistry.SaveSetting(Section, ControlName, nud.Value); } } else if (((Kind & FormSaveRestoreKind.ListControl) == FormSaveRestoreKind.ListControl) && (TypeCur.BaseType == typeof(ListControl))) { ListControl lst = (ListControl)ctl; SaveListControlSelectedIndex(AppProductName, FrmOrUc, lst, xc); } else if (((Kind & FormSaveRestoreKind.CheckBox) == FormSaveRestoreKind.CheckBox) && (TypeCur == typeof(CheckBox))) { CheckBox chk = (CheckBox)ctl; if (xc != null) { xc.SaveSetting(FrmOrUcName + "." + ControlName, CFindRep.IfTrueThen1FalseThen0(chk.Checked)); } else { CRegistry.SaveSetting(Section, ControlName, CFindRep.IfTrueThen1FalseThen0(chk.Checked)); } } } } }