Changeset 15 for Common/ComboBoxEx.cs
- Timestamp:
- Jun 18, 2024, 12:15:33 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/ComboBoxEx.cs
r14 r15 8 8 public partial class ComboBoxEx : ComboBox 9 9 { 10 public string regSubKey;11 public int maxHistoryCount;10 public string RegSubKey; 11 public int MaxHistoryCount; 12 12 13 13 public ComboBoxEx() 14 14 { 15 15 InitializeComponent(); 16 regSubKey = Name;17 maxHistoryCount = 20;16 RegSubKey = Name; 17 MaxHistoryCount = 20; 18 18 } 19 19 … … 23 23 { 24 24 BeginUpdate(); 25 string previousText = Text; 26 int index = Items.IndexOf(Text); 27 if (index >= 0) Items.RemoveAt(index); 28 Text = previousText; 29 Items.Insert(0, previousText); 25 try 26 { 27 string previousText = Text; 28 int index = Items.IndexOf(Text); 29 if (index >= 0) Items.RemoveAt(index); 30 Text = previousText; 31 Items.Insert(0, previousText); 30 32 31 while (Items.Count > maxHistoryCount) 32 Items.RemoveAt(Items.Count - 1); 33 EndUpdate(); 33 while (Items.Count > MaxHistoryCount) 34 Items.RemoveAt(Items.Count - 1); 35 } 36 finally 37 { 38 EndUpdate(); 39 } 34 40 } 35 41 } … … 37 43 public void LoadFromRegistry() 38 44 { 39 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey( regSubKey);40 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey);45 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey) ?? 46 Application.UserAppDataRegistry.CreateSubKey(RegSubKey); 41 47 42 48 int count = regKey.GetValueInt("Count", 0); 43 49 BeginUpdate(); 44 while (Items.Count > count) Items.RemoveAt(Items.Count - 1); 45 while (Items.Count < count) Items.Add(""); 46 for (int i = 0; i < count; i++) 50 try 47 51 { 48 Items[i] = (string)regKey.GetValue(i.ToString(), ""); 52 while (Items.Count > count) Items.RemoveAt(Items.Count - 1); 53 while (Items.Count < count) Items.Add(""); 54 for (int i = 0; i < count; i++) 55 { 56 Items[i] = (string)regKey.GetValue(i.ToString(), ""); 57 } 49 58 } 50 EndUpdate(); 59 finally 60 { 61 EndUpdate(); 62 } 51 63 } 52 64 53 65 public void SaveToRegistry() 54 66 { 55 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey( regSubKey, true);56 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey);67 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey, true) ?? 68 Application.UserAppDataRegistry.CreateSubKey(RegSubKey); 57 69 58 70 int i = 0;
Note:
See TracChangeset
for help on using the changeset viewer.