Changeset 3


Ignore:
Timestamp:
Feb 21, 2019, 2:13:01 PM (5 years ago)
Author:
chronos
Message:
  • Added: Extended ComboBox with text history support.
Location:
Common
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • Common/FormFind.Designer.cs

    r2 r3  
    3535            this.checkBoxMatchCase = new System.Windows.Forms.CheckBox();
    3636            this.buttonFindPrevious = new System.Windows.Forms.Button();
    37             this.comboBoxWhat = new System.Windows.Forms.ComboBox();
     37            this.comboBoxWhat = new Common.ComboBoxEx();
    3838            this.SuspendLayout();
    3939            //
     
    154154        private System.Windows.Forms.CheckBox checkBoxMatchCase;
    155155        private System.Windows.Forms.Button buttonFindPrevious;
    156         private System.Windows.Forms.ComboBox comboBoxWhat;
     156        private Common.ComboBoxEx comboBoxWhat;
    157157    }
    158158}
  • Common/FormFind.cs

    r2 r3  
    1616        public RichTextBoxEx richTextBox;
    1717        public string regSubKey;
    18         public int maxHistoryCount;
    1918
    2019        public FormFind()
     
    2221            InitializeComponent();
    2322            regSubKey = "Find";
    24             maxHistoryCount = 20;
    2523        }
    2624
     
    6058        private void SearchText(bool reverse = false)
    6159        {
    62             if (comboBoxWhat.Text.Trim() != "")
    63             {
    64                 string previousText = comboBoxWhat.Text;
    65                 int index = comboBoxWhat.Items.IndexOf(comboBoxWhat.Text);
    66                 if (index >= 0) comboBoxWhat.Items.RemoveAt(index);
    67                 comboBoxWhat.Text = previousText;
    68                 comboBoxWhat.Items.Insert(0, comboBoxWhat.Text);
    69                
    70                 while (comboBoxWhat.Items.Count > maxHistoryCount)
    71                     comboBoxWhat.Items.RemoveAt(comboBoxWhat.Items.Count - 1);
    72             }
     60            comboBoxWhat.UpdateHistory();
    7361
    7462            while (true)
     
    11199            new FormDimensions().Load(this, Owner);
    112100            comboBoxWhat.Focus();
     101            comboBoxWhat.regSubKey = regSubKey + "\\History";
    113102            LoadFromRegistry();
    114103            UpdateInterface();
     
    153142            checkBoxMatchCase.Checked = regKey.GetValueBool("MatchCase", false);
    154143
    155             regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey + "\\History");
    156             if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey + "\\History");
    157             int count = regKey.GetValueInt("Count", 0);
    158             comboBoxWhat.BeginUpdate();
    159             while (comboBoxWhat.Items.Count > count) comboBoxWhat.Items.RemoveAt(comboBoxWhat.Items.Count - 1);
    160             while (comboBoxWhat.Items.Count < count) comboBoxWhat.Items.Add("");
    161             for (int i = 0; i < count; i++)
    162             {
    163                 comboBoxWhat.Items[i] = (string)regKey.GetValue(i.ToString(), "");
    164             }
    165             comboBoxWhat.EndUpdate();
     144            comboBoxWhat.LoadFromRegistry();
    166145        }
    167146
     
    171150            if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey);
    172151
     152           
    173153            regKey.SetValue("MatchWholeWordOnly", checkBoxMatchWholeWordOnly.Checked);
    174154            regKey.SetValue("MatchCase", checkBoxMatchCase.Checked);
    175155
    176             regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey + "\\History", true);
    177             if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey + "\\History");
    178 
    179             int i = 0;
    180             regKey.SetValue("Count", comboBoxWhat.Items.Count);
    181             foreach (var item in comboBoxWhat.Items)
    182             {
    183                 regKey.SetValue(i.ToString(), item);
    184                 i++;
    185             }
    186 
    187             while (true)
    188             {
    189                 List<string> names = regKey.GetValueNames().ToList();
    190                 if (names.IndexOf(i.ToString()) != -1)
    191                 {
    192                     regKey.DeleteValue(i.ToString());
    193                 }
    194                 else break;
    195                 i++;
    196             }
     156            comboBoxWhat.SaveToRegistry();
    197157        }
    198158    }
  • Common/Theme.cs

    r1 r3  
    1212    public class Theme
    1313    {
     14        public delegate void ApplyThemeHandler(Component component);
     15        static public event ApplyThemeHandler OnApplyTheme = null;
    1416        static public Color ColorWindow;
    1517        static public Color ColorWindowText;
     
    9597                (component as LinkLabel).VisitedLinkColor = ColorControlText;
    9698            } else
    97             if (component is TabControl) 
     99            if (component is TabControl)
    98100            {
    99101                foreach (TabPage tabPage in (component as TabControl).TabPages)
     
    132134                (component as DataGridView).ColumnHeadersDefaultCellStyle.BackColor = ColorWindow;
    133135                (component as DataGridView).ColumnHeadersDefaultCellStyle.ForeColor = ColorWindowText;
    134             }
     136            } else
     137            if (component is RichTextBox)
     138            {
     139                (component as RichTextBox).SelectAll();
     140                (component as RichTextBox).SelectionColor = ColorWindowText;
     141                (component as RichTextBox).SelectionLength = 0;
     142            } else
     143           
     144            OnApplyTheme(component);
    135145        }
    136146
Note: See TracChangeset for help on using the changeset viewer.