Changeset 15 for Common/FormDimensions.cs
- Timestamp:
- Jun 18, 2024, 12:15:33 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/FormDimensions.cs
r14 r15 7 7 namespace Common 8 8 { 9 class FormDimensions9 public class FormDimensions 10 10 { 11 11 public Form Form; … … 45 45 const UInt32 SW_RESTORE = 9; 46 46 47 private WINDOWPLACEMENT GetPlacement(Form form)47 private static WINDOWPLACEMENT GetPlacement(Form form) 48 48 { 49 49 WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); … … 53 53 } 54 54 55 private bool IsVisibleOnAnyScreen(Rectangle rect)56 { 57 int minVisible = 50;55 private static bool IsVisibleOnAnyScreen(Rectangle rect) 56 { 57 const int minVisible = 50; 58 58 foreach (Screen screen in Screen.AllScreens) 59 59 { … … 70 70 public void Load(Form form, Form parentForm = null) 71 71 { 72 this.Form = form;73 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name) ;74 if (regKey == null) regKey =Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name);72 Form = form; 73 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name) ?? 74 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name); 75 75 76 76 string name = ""; … … 138 138 form.WindowState = FormWindowState.Maximized; 139 139 break; 140 default:141 break;142 140 } 143 141 form.Visible = prevVisibleState; … … 147 145 public void Save(Form form, Form parentForm = null) 148 146 { 149 this.Form = form;150 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name, true) ;151 if (regKey == null) regKey =Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name);147 Form = form; 148 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name, true) ?? 149 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name); 152 150 153 151 string name = ""; … … 186 184 public void LoadControl(Control control) 187 185 { 188 if (control is ListView) 189 { 190 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 191 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 192 193 for (int I = 0; I < (control as ListView).Columns.Count; I++) 194 { 195 if (regKey.GetValue("ColWidth" + I.ToString()) != null) 196 (control as ListView).Columns[I].Width = (int) regKey.GetValue("ColWidth" + I.ToString()); 197 } 198 } else 199 if (control is DataGridView) 200 { 201 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 202 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 203 204 for (int I = 0; I < (control as DataGridView).Columns.Count; I++) 205 { 206 if (regKey.GetValue("ColWidth" + I.ToString()) != null) 207 (control as DataGridView).Columns[I].Width = (int)regKey.GetValue("ColWidth" + I.ToString()); 208 } 209 } 210 if (control is SplitContainer) 211 { 212 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 213 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 214 215 if (regKey.GetValue("SplitterDistance") != null) 216 (control as SplitContainer).SplitterDistance = (int)regKey.GetValue("SplitterDistance"); 186 switch (control) 187 { 188 case ListView listView: 189 { 190 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + listView.Name, true) ?? 191 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + listView.Name); 192 193 for (int I = 0; I < listView.Columns.Count; I++) 194 { 195 object value = regKey.GetValue(listView.Columns[I].Text); 196 if (value != null) listView.Columns[I].Width = (int)value; 197 } 198 199 break; 200 } 201 case DataGridView dataGridView: 202 { 203 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + dataGridView.Name, true) ?? 204 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + dataGridView.Name); 205 206 for (int I = 0; I < dataGridView.Columns.Count; I++) 207 { 208 object value = regKey.GetValue("ColWidth" + I); 209 if (value != null) dataGridView.Columns[I].Width = (int)value; 210 } 211 212 break; 213 } 214 case SplitContainer splitContainer: 215 { 216 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + splitContainer.Name, true) ?? 217 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + splitContainer.Name); 218 219 object value = regKey.GetValue("SplitterDistance"); 220 if (value != null) 221 splitContainer.SplitterDistance = (int)value; 222 break; 223 } 217 224 } 218 225 … … 225 232 public void SaveControl(Control control) 226 233 { 227 if (control is ListView) 228 { 229 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 230 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 231 232 for (int I = 0; I < (control as ListView).Columns.Count; I++) 233 { 234 regKey.SetValue("ColWidth" + I.ToString(), (control as ListView).Columns[I].Width); 235 } 236 } else 237 if (control is DataGridView) 238 { 239 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 240 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 241 242 for (int I = 0; I < (control as DataGridView).Columns.Count; I++) 243 { 244 regKey.SetValue("ColWidth" + I.ToString(), (control as DataGridView).Columns[I].Width); 245 } 246 } 247 if (control is SplitContainer) 248 { 249 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name, true); 250 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + control.Name); 251 252 regKey.SetValue("SplitterDistance", (control as SplitContainer).SplitterDistance); 234 switch (control) 235 { 236 case ListView listView: 237 { 238 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + listView.Name, true) ?? 239 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + listView.Name); 240 241 for (int I = 0; I < listView.Columns.Count; I++) 242 { 243 regKey.SetValue(listView.Columns[I].Text, listView.Columns[I].Width); 244 } 245 246 break; 247 } 248 case DataGridView dataGridView: 249 { 250 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + dataGridView.Name, true) ?? 251 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + dataGridView.Name); 252 253 for (int I = 0; I < dataGridView.Columns.Count; I++) 254 { 255 regKey.SetValue("ColWidth" + I, dataGridView.Columns[I].Width); 256 } 257 258 break; 259 } 260 case SplitContainer splitContainer: 261 { 262 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + Form.Name + "\\" + splitContainer.Name, true) ?? 263 Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + Form.Name + "\\" + splitContainer.Name); 264 265 regKey.SetValue("SplitterDistance", splitContainer.SplitterDistance); 266 break; 267 } 253 268 } 254 269
Note:
See TracChangeset
for help on using the changeset viewer.