Esempio n. 1
0
        /// <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));
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <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 RestoreFormStatus(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;

                int LeftWill, TopWill;

                int    WindowStateDefault = (int)FormWindowState.Normal;
                object WindowState        =
                    (xc != null) ?
                    xc.GetSetting(FrmOrUcName + ".WindowState", WindowStateDefault) :
                    CRegistry.GetSetting(Section, "WindowState", WindowStateDefault);

                FormWindowState ws = FormWindowState.Normal;
                try { ws = (FormWindowState)Convert.ToInt32(WindowState); }
                catch (Exception) { }

                if (frm.WindowState != ws)
                {
                    frm.WindowState = ws;
                }

                if (ws == FormWindowState.Normal)
                {
                    int    LeftDefault = frm.Left;
                    object Left        =
                        (xc != null) ?
                        xc.GetSetting(FrmOrUcName + ".Left", LeftDefault) :
                        CRegistry.GetSetting(Section, "Left", LeftDefault);

                    LeftWill = Convert.ToInt32(Left);
                    if (LeftWill < 0)
                    {
                        LeftWill = 0;
                    }

                    int    TopDefault = frm.Top;
                    object Top        =
                        (xc != null) ?
                        xc.GetSetting(FrmOrUcName + ".Top", TopDefault) :
                        CRegistry.GetSetting(Section, "Top", TopDefault);

                    TopWill = Convert.ToInt32(Top);
                    if (TopWill < 0)
                    {
                        TopWill = 0;
                    }

                    if (frm.Left != LeftWill)
                    {
                        frm.Left = LeftWill;
                    }
                    if (frm.Top != TopWill)
                    {
                        frm.Top = TopWill;
                    }

                    switch (frm.FormBorderStyle)
                    {
                    case FormBorderStyle.Fixed3D:
                    case FormBorderStyle.FixedDialog:
                    case FormBorderStyle.FixedSingle:
                    case FormBorderStyle.FixedToolWindow:
                        break;

                    default:
                        int    WidthDefault = frm.Width;
                        object Width        =
                            (xc != null) ?
                            xc.GetSetting(FrmOrUcName + ".Width", WidthDefault) :
                            CRegistry.GetSetting(Section, "Width", WidthDefault);

                        int WidthWill = Convert.ToInt32(Width);
                        if (frm.Width != WidthWill)
                        {
                            frm.Width = WidthWill;
                        }

                        int    HeightDefault = frm.Height;
                        object Height        =
                            (xc != null) ?
                            xc.GetSetting(FrmOrUcName + ".Height", HeightDefault) :
                            CRegistry.GetSetting(Section, "Height", HeightDefault);

                        int HeightWill = Convert.ToInt32(Height);
                        if (frm.Height != HeightWill)
                        {
                            frm.Height = HeightWill;
                        }

                        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;

                        string Value =
                            (xc != null) ?
                            xc.GetSetting(FrmOrUcName + "." + ControlName, txt.Text) :
                            CRegistry.GetSetting(Section, ControlName, txt.Text).ToString();

                        if (txt.Text != Value)
                        {
                            txt.Text = Value;
                        }
                    }
                    else if (((Kind & FormSaveRestoreKind.NumericUpDown) == FormSaveRestoreKind.NumericUpDown) && (TypeCur == typeof(NumericUpDown)))
                    {
                        NumericUpDown nud = (NumericUpDown)ctl;

                        string Value =
                            (xc != null) ?
                            xc.GetSetting(FrmOrUcName + "." + ControlName, nud.Value) :
                            CRegistry.GetSetting(Section, ControlName, nud.Value).ToString();

                        if (nud.Value.ToString() != Value)
                        {
                            nud.Value = (decimal)CFindRep.IfNotNumberThen0Decimal(Value);
                        }
                    }
                    else if (((Kind & FormSaveRestoreKind.ListControl) == FormSaveRestoreKind.ListControl) && (TypeCur.BaseType == typeof(ListControl)))
                    {
                        ListControl lst = (ListControl)ctl;
                        RestoreListControlSelectedIndex(Application.ProductName, FrmOrUc, lst, xc);
                    }
                    else if (((Kind & FormSaveRestoreKind.CheckBox) == FormSaveRestoreKind.CheckBox) && (TypeCur == typeof(CheckBox)))
                    {
                        CheckBox chk = (CheckBox)ctl;

                        bool Checked =
                            (xc != null) ?
                            (xc.GetSetting(FrmOrUcName + "." + ControlName, CFindRep.IfTrueThen1FalseThen0(chk.Checked)) == "1") :
                            (CRegistry.GetSetting(Section, ControlName, CFindRep.IfTrueThen1FalseThen0(chk.Checked)).ToString() == "1");

                        if (chk.Checked != Checked)
                        {
                            chk.Checked = Checked;
                        }
                    }
                    else if (((Kind & FormSaveRestoreKind.RadioButton) == FormSaveRestoreKind.RadioButton) && (TypeCur == typeof(RadioButton)))
                    {
                        RadioButton rad = (RadioButton)ctl;

                        bool Checked =
                            (xc != null) ?
                            (xc.GetSetting(FrmOrUcName + "." + ControlName, CFindRep.IfTrueThen1FalseThen0(rad.Checked)) == "1") :
                            (CRegistry.GetSetting(Section, ControlName, CFindRep.IfTrueThen1FalseThen0(rad.Checked)).ToString() == "1");

                        if (rad.Checked != Checked)
                        {
                            rad.Checked = Checked;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public static void RestoreListControlSelectedIndex(string AppProductName, ContainerControl FrmOrUc, ListControl lst, CXmlConfig xc)
        {
            string FrmOrUcName = FrmOrUc.Name;
            string Section     = AppProductName + "\\" + FrmOrUcName;
            string ControlName = lst.Name;

            int SelectedIndex =
                (xc != null) ?
                CFindRep.IfNotNumberThen0(xc.GetSetting(FrmOrUcName + "." + ControlName, lst.SelectedIndex)) :
                CFindRep.IfNotNumberThen0(CRegistry.GetSetting(Section, ControlName, lst.SelectedIndex));

            if (lst.SelectedIndex != SelectedIndex)
            {
                //Items.Count 읽을 수 없어 try 사용.
                try { lst.SelectedIndex = SelectedIndex; }
                catch (Exception) { }
            }
        }
Esempio n. 4
0
        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);
            }
        }