コード例 #1
0
            private void InitializeComponents()
            {
                this.Controls.AddRange(new Control[] { lblSections, cmbSections, lblKeys,
                                                       cmbKeys, lblDefault, txtDefault, lblOld, txtOld, lblNew,
                                                       txtNew, btnBrowse, btnSave, btnCancel });

                txtDefault.SetAutoShowScroll(ScrollBars.Vertical);
                txtOld.SetAutoShowScroll(ScrollBars.Vertical);
                txtNew.SetAutoShowScroll(ScrollBars.Vertical);
                txtDefault.CanSelectAllWhenReadOnly();
                txtOld.CanSelectAllWhenReadOnly();
                cmbSections.AutosizeDropDownWidth();
                cmbKeys.AutosizeDropDownWidth();

                int a = 20.DpiZoom();

                lblSections.Top = lblSections.Left = cmbSections.Top = lblKeys.Left
                                                                           = lblDefault.Left = lblOld.Left = lblNew.Left = btnBrowse.Left = a;

                lblKeys.Top       = cmbKeys.Top = cmbSections.Bottom + a;
                lblDefault.Top    = txtDefault.Top = cmbKeys.Bottom + a;
                txtDefault.Height = txtOld.Height = txtNew.Height = 4 * a;
                cmbSections.Width = cmbKeys.Width = txtDefault.Width = txtOld.Width = txtNew.Width = 20 * a;

                int h = cmbSections.Height + cmbKeys.Height + btnBrowse.Height;

                int[] ws = { lblSections.Width, lblKeys.Width, lblDefault.Width, lblOld.Width, lblNew.Width };
                int   w  = ws.Max();

                cmbSections.Left = cmbKeys.Left = txtDefault.Left = txtOld.Left = txtNew.Left = w + 2 * a;

                this.Resize += (sender, e) =>
                {
                    txtDefault.Height = txtOld.Height = txtNew.Height
                                                            = (this.ClientSize.Height - h - 7 * a) / 3;

                    lblOld.Top    = txtOld.Top = txtDefault.Bottom + a;
                    lblNew.Top    = txtNew.Top = txtOld.Bottom + a;
                    btnBrowse.Top = btnSave.Top = btnCancel.Top = txtNew.Bottom + a;

                    cmbSections.Width = cmbKeys.Width = txtDefault.Width = txtOld.Width = txtNew.Width
                                                                                              = this.ClientSize.Width - (w + 3 * a);

                    btnCancel.Left = this.ClientSize.Width - btnCancel.Width - a;
                    btnSave.Left   = btnCancel.Left - btnSave.Width - 2 * a;
                    btnBrowse.Left = btnSave.Left - btnBrowse.Width - 2 * a;
                };
                this.ClientSize  = new Size(w + 23 * a, h + 3 * 4 * a + 7 * a);
                this.MinimumSize = this.Size;

                cmbSections.Items.AddRange(DefaultDic.Keys.ToArray());
                cmbSections.SelectedIndexChanged += (sender, e) =>
                {
                    cmbKeys.Items.Clear();
                    cmbKeys.Items.AddRange(DefaultDic[Section].Keys.ToArray());
                    cmbKeys.SelectedIndex = 0;
                };
                cmbKeys.SelectedIndexChanged += (sender, e) =>
                {
                    txtNew.Text     = EditingDic[Section][Key].Replace("\\n", Environment.NewLine);
                    txtDefault.Text = DefaultDic[Section][Key].Replace("\\n", Environment.NewLine);
                    txtOld.Text     = ReferentialWirter.GetValue(Section, Key).Replace("\\n", Environment.NewLine);
                };
                cmbSections.SelectedIndex = 0;

                txtOld.TextChanged += (sender, e) => { if (txtNew.Text == string.Empty)
                                                       {
                                                           txtNew.Text = txtOld.Text;
                                                       }
                };
                txtNew.TextChanged += (sender, e) => EditingDic[Section][Key] = txtNew.Text.Replace(Environment.NewLine, "\\n");
                btnBrowse.Click    += (sender, e) => SelectFile();
                btnSave.Click      += (sender, e) => Save();
            }