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); } }
//http://stackoverflow.com/questions/17922308/use-latest-version-of-ie-in-webbrowser-control public static void SetWebBrowserControlVersion(string ProcessNameWithExtension, int IeVersionMajor) { int nBrowserEmulationNew = (int)BrowserEmulation._07Doctype; if (IeVersionMajor >= 11) { nBrowserEmulationNew = (int)BrowserEmulation._11IgnoreDoctype; } else if (IeVersionMajor >= 10) { nBrowserEmulationNew = (int)BrowserEmulation._10IgnoreDoctype; } else if (IeVersionMajor >= 9) { nBrowserEmulationNew = (int)BrowserEmulation._09IgnoreDoctype; } else if (IeVersionMajor >= 8) { nBrowserEmulationNew = (int)BrowserEmulation._08IgnoreDoctype; } else if (IeVersionMajor >= 7) { nBrowserEmulationNew = (int)BrowserEmulation._07Doctype; } //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION //(When 64bit OS, the value will save to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\... node.) string Section = @"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION"; object oValue = CRegistry.GetSetting(HRootKeys.HKEY_LOCAL_MACHINE, Section, ProcessNameWithExtension, (int)BrowserEmulation._07Doctype); int nBrowserEmulationOld = Convert.ToInt32(oValue); if (nBrowserEmulationNew != nBrowserEmulationOld) { CRegistry.SaveSetting(HRootKeys.HKEY_LOCAL_MACHINE, Section, ProcessNameWithExtension, nBrowserEmulationNew, RegistryValueKind.DWord); } }
/// <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)); } } } } }