Changeset 2 for Common/FormFind.cs
- Timestamp:
- Feb 14, 2019, 5:29:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/FormFind.cs
r1 r2 8 8 using System.Threading.Tasks; 9 9 using System.Windows.Forms; 10 using Microsoft.Win32; 10 11 11 12 namespace Common … … 14 15 { 15 16 public RichTextBoxEx richTextBox; 16 FormDimensions formDimensions; 17 public string regSubKey; 18 public int maxHistoryCount; 17 19 18 20 public FormFind() 19 21 { 20 22 InitializeComponent(); 21 formDimensions = new FormDimensions(); 23 regSubKey = "Find"; 24 maxHistoryCount = 20; 22 25 } 23 26 … … 57 60 private void SearchText(bool reverse = false) 58 61 { 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 } 73 59 74 while (true) 60 75 { 61 int newPos = FindText( textBoxWhat.Text.Trim(), richTextBox.SelectionStart, richTextBox.SelectionLength, reverse);76 int newPos = FindText(comboBoxWhat.Text.Trim(), richTextBox.SelectionStart, richTextBox.SelectionLength, reverse); 62 77 if (newPos >= 0) 63 78 { 64 79 richTextBox.SelectionColor = Color.Red; 65 richTextBox.Select(newPos, textBoxWhat.Text.Length);80 richTextBox.Select(newPos, comboBoxWhat.Text.Length); 66 81 richTextBox.ScrollToCaret(); 67 82 } … … 94 109 DpiScaling.Apply(this); 95 110 this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 96 formDimensions.Load(this, Owner); 97 textBoxWhat.Focus(); 111 new FormDimensions().Load(this, Owner); 112 comboBoxWhat.Focus(); 113 LoadFromRegistry(); 98 114 UpdateInterface(); 99 115 } … … 106 122 private void FormFind_FormClosing(object sender, FormClosingEventArgs e) 107 123 { 124 SaveToRegistry(); 108 125 richTextBox.formFind = null; 109 formDimensions.Save(this, Owner);126 new FormDimensions().Save(this, Owner); 110 127 } 111 128 … … 115 132 { 116 133 buttonFindNext.PerformClick(); 134 } else 135 if (e.KeyChar == 27) 136 { 137 Close(); 117 138 } 118 139 } … … 120 141 private void UpdateInterface() 121 142 { 122 buttonFindNext.Enabled = textBoxWhat.Text.Length > 0; 123 buttonFindPrevious.Enabled = textBoxWhat.Text.Length > 0; 143 buttonFindNext.Enabled = comboBoxWhat.Text.Length > 0; 144 buttonFindPrevious.Enabled = comboBoxWhat.Text.Length > 0; 145 } 146 147 public void LoadFromRegistry() 148 { 149 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey); 150 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey); 151 152 checkBoxMatchWholeWordOnly.Checked = regKey.GetValueBool("MatchWholeWordOnly", false); 153 checkBoxMatchCase.Checked = regKey.GetValueBool("MatchCase", false); 154 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(); 166 } 167 168 public void SaveToRegistry() 169 { 170 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey, true); 171 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey); 172 173 regKey.SetValue("MatchWholeWordOnly", checkBoxMatchWholeWordOnly.Checked); 174 regKey.SetValue("MatchCase", checkBoxMatchCase.Checked); 175 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 } 124 197 } 125 198 }
Note:
See TracChangeset
for help on using the changeset viewer.