Changeset 14
- Timestamp:
- Aug 2, 2022, 11:46:25 AM (2 years ago)
- Location:
- Common
- Files:
-
- 4 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/ComboBoxEx.Designer.cs
r3 r14 1 namespace Common1 namespace Common 2 2 { 3 3 partial class ComboBoxEx -
Common/ComboBoxEx.cs
r13 r14 1 using System;2 1 using System.Collections.Generic; 3 using System.ComponentModel;4 using System.Diagnostics;5 2 using System.Linq; 6 using System.Text;7 3 using System.Windows.Forms; 8 4 using Microsoft.Win32; 9 using Common;10 5 11 6 namespace Common … … 27 22 if (Text.Trim() != "") 28 23 { 24 BeginUpdate(); 29 25 string previousText = Text; 30 26 int index = Items.IndexOf(Text); … … 35 31 while (Items.Count > maxHistoryCount) 36 32 Items.RemoveAt(Items.Count - 1); 33 EndUpdate(); 37 34 } 38 35 } -
Common/CsvExport.cs
r1 r14 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 2 using System.Text; 5 3 using System.IO; 6 4 using System.Windows.Forms; 7 using System.Threading.Tasks;8 5 9 6 namespace Common … … 11 8 class CsvExport 12 9 { 13 public void ListViewToC SV(ListView listView, string filePath, bool includeHidden)10 public void ListViewToCsv(ListView listView, string filePath, bool includeHidden) 14 11 { 15 12 // Make header string 16 13 StringBuilder result = new StringBuilder(); 17 WriteC SVRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listView.Columns[i].Text);14 WriteCsvRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listView.Columns[i].Text); 18 15 19 16 // Export data rows 20 17 foreach (ListViewItem listItem in listView.Items) 21 WriteC SVRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listItem.SubItems[i].Text);18 WriteCsvRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listItem.SubItems[i].Text); 22 19 23 20 File.WriteAllText(filePath, result.ToString()); 24 21 } 25 22 26 public void DataGridViewToC SV(DataGridView dataGridView, string filePath, bool includeHidden)23 public void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden) 27 24 { 28 25 // Make header string 29 26 StringBuilder result = new StringBuilder(); 30 WriteC SVRow(result, dataGridView.Columns.Count, i => includeHidden || dataGridView.Columns[i].Width > 0, i => dataGridView.Columns[i].HeaderText);27 WriteCsvRow(result, dataGridView.Columns.Count, i => includeHidden || dataGridView.Columns[i].Width > 0, i => dataGridView.Columns[i].HeaderText); 31 28 32 29 // Export data rows 33 30 foreach (DataGridViewRow row in dataGridView.Rows) 34 WriteC SVRow(result, row.Cells.Count, i => includeHidden || row.Cells[i].Size.Width > 0, i => row.Cells[i].Value.ToString());31 WriteCsvRow(result, row.Cells.Count, i => includeHidden || row.Cells[i].Size.Width > 0, i => row.Cells[i].Value.ToString()); 35 32 36 33 File.WriteAllText(filePath, result.ToString()); 37 34 } 38 35 39 private void WriteC SVRow(StringBuilder result, int itemsCount, Func<int, bool> isColumnNeeded, Func<int, string> columnValue)36 private void WriteCsvRow(StringBuilder result, int itemsCount, Func<int, bool> isColumnNeeded, Func<int, string> columnValue) 40 37 { 41 38 bool isFirstTime = true; -
Common/DpiScaling.cs
r1 r14 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 1 using System.Windows.Forms; 7 2 using System.Drawing; 8 3 using System.ComponentModel; 4 using Microsoft.Win32; 9 5 10 6 namespace Common … … 12 8 class DpiScaling 13 9 { 14 public static float systemDpi = 0;15 public static bool useCustomDpi = false;16 public static float customDpi = 96;17 private static bool changed = false;10 public static float SystemDpi; 11 public static bool UseCustomDpi; 12 public static float CustomDpi = 96; 13 private static bool _changed; 18 14 19 15 public static void ApplyToComponent(Component component) … … 29 25 { 30 26 //(component as ToolStrip).AutoSize = false; 31 Size newSize = new Size((int)((component as ToolStrip).ImageScalingSize.Width * customDpi / 96F),32 (int)((component as ToolStrip).ImageScalingSize.Height * customDpi / 96F));27 Size newSize = new Size((int)((component as ToolStrip).ImageScalingSize.Width * CustomDpi / 96F), 28 (int)((component as ToolStrip).ImageScalingSize.Height * CustomDpi / 96F)); 33 29 /* foreach (ToolStripItem item in (component as ToolStrip).Items) 34 30 { … … 58 54 if (component is MenuStrip) 59 55 { 60 (component as MenuStrip).Font = new System.Drawing.Font((component as MenuStrip).Font.FontFamily, 8.25F * customDpi / 96F,61 (component as MenuStrip).Font.Style, System.Drawing.GraphicsUnit.Point, (component as MenuStrip).Font.GdiCharSet);56 (component as MenuStrip).Font = new Font((component as MenuStrip).Font.FontFamily, 8.25F * CustomDpi / 96F, 57 (component as MenuStrip).Font.Style, GraphicsUnit.Point, (component as MenuStrip).Font.GdiCharSet); 62 58 } 63 59 if (component is TabControl) … … 70 66 if (component is ToolStripItem) 71 67 { 72 (component as ToolStripItem).Font = new System.Drawing.Font((component as ToolStripItem).Font.FontFamily, 8.25F * customDpi / 96F,73 (component as ToolStripItem).Font.Style, System.Drawing.GraphicsUnit.Point, (component as ToolStripItem).Font.GdiCharSet);68 (component as ToolStripItem).Font = new Font((component as ToolStripItem).Font.FontFamily, 8.25F * CustomDpi / 96F, 69 (component as ToolStripItem).Font.Style, GraphicsUnit.Point, (component as ToolStripItem).Font.GdiCharSet); 74 70 } 75 71 } … … 77 73 public static void Apply(Form form) 78 74 { 79 if ( useCustomDpi)changed = true;80 if ( systemDpi == 0)75 if (UseCustomDpi) _changed = true; 76 if (SystemDpi == 0) 81 77 { 82 78 Graphics graphics = form.CreateGraphics(); 83 systemDpi = graphics.DpiX;79 SystemDpi = graphics.DpiX; 84 80 } 85 if ( useCustomDpi ||changed)81 if (UseCustomDpi || _changed) 86 82 { 87 form.Font = new System.Drawing.Font(form.Font.FontFamily, 8.25F * customDpi / 96F,88 form.Font.Style, System.Drawing.GraphicsUnit.Point, form.Font.GdiCharSet);83 form.Font = new Font(form.Font.FontFamily, 8.25F * CustomDpi / 96F, 84 form.Font.Style, GraphicsUnit.Point, form.Font.GdiCharSet); 89 85 ApplyToComponent(form); 90 86 } 91 87 } 92 88 93 public static float Scale(float size )89 public static float Scale(float size, float baseDpi = 96F) 94 90 { 95 if (useCustomDpi) size = size * customDpi / 96F; 91 if (UseCustomDpi) 92 { 93 size = size * CustomDpi / baseDpi; 94 } 95 else 96 { 97 size = size * SystemDpi / baseDpi; 98 } 99 96 100 return size; 101 } 102 103 public static void LoadFromRegistry(string regSubKey = "") 104 { 105 if (Application.UserAppDataRegistry == null) return; 106 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey); 107 if (regKey == null) return; 108 109 CustomDpi = regKey.GetValueInt("CustomDpiEnabled", (int)CustomDpi); 110 UseCustomDpi = regKey.GetValueBool("StackTrace", UseCustomDpi); 111 } 112 113 public static void SaveToRegistry(string regSubKey = "") 114 { 115 if (Application.UserAppDataRegistry == null) return; 116 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey, true); 117 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey); 118 119 regKey.SetValueInt("CustomDpiEnabled", (int)CustomDpi); 120 regKey.SetValueBool("StackTrace", UseCustomDpi); 97 121 } 98 122 } -
Common/FileExt.cs
r5 r14 23 23 } else File.WriteAllText(fileName, content); 24 24 } 25 26 public static string GetExactPathName(string pathName) 27 { 28 if (!(File.Exists(pathName) || Directory.Exists(pathName))) 29 return pathName; 30 31 var di = new DirectoryInfo(pathName); 32 33 if (di.Parent != null) 34 { 35 return Path.Combine( 36 GetExactPathName(di.Parent.FullName), 37 di.Parent.GetFileSystemInfos(di.Name)[0].Name); 38 } 39 else 40 { 41 return di.FullName.ToUpper(); 42 } 43 } 25 44 } 26 45 } -
Common/FormDimensions.cs
r12 r14 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.Drawing; 6 3 using System.Windows.Forms; … … 12 9 class FormDimensions 13 10 { 14 public Form form;11 public Form Form; 15 12 public string RegSubKey; 16 public FormWindowState defaultFormWindowState = FormWindowState.Normal;13 public FormWindowState DefaultFormWindowState = FormWindowState.Normal; 17 14 18 15 [DllImport("user32.dll")] … … 73 70 public void Load(Form form, Form parentForm = null) 74 71 { 75 this. form = form;72 this.Form = form; 76 73 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name); 77 74 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name); … … 103 100 (int)regKey.GetValue("RestoreBoundsWidth" + name, restoreBounds.Width), 104 101 (int)regKey.GetValue("RestoreBoundsHeight" + name, restoreBounds.Height)); 105 FormWindowState windowState = (FormWindowState)regKey.GetValue("State" + name, (int) defaultFormWindowState);102 FormWindowState windowState = (FormWindowState)regKey.GetValue("State" + name, (int)DefaultFormWindowState); 106 103 if (parentForm != null) 107 104 { … … 150 147 public void Save(Form form, Form parentForm = null) 151 148 { 152 this. form = form;149 this.Form = form; 153 150 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name, true); 154 151 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name); … … 191 188 if (control is ListView) 192 189 { 193 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);194 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 195 192 196 193 for (int I = 0; I < (control as ListView).Columns.Count; I++) … … 202 199 if (control is DataGridView) 203 200 { 204 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);205 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 206 203 207 204 for (int I = 0; I < (control as DataGridView).Columns.Count; I++) … … 213 210 if (control is SplitContainer) 214 211 { 215 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);216 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 217 214 218 215 if (regKey.GetValue("SplitterDistance") != null) … … 230 227 if (control is ListView) 231 228 { 232 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);233 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 234 231 235 232 for (int I = 0; I < (control as ListView).Columns.Count; I++) … … 240 237 if (control is DataGridView) 241 238 { 242 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);243 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 244 241 245 242 for (int I = 0; I < (control as DataGridView).Columns.Count; I++) … … 250 247 if (control is SplitContainer) 251 248 { 252 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name, true);253 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name + "\\" + control.Name);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); 254 251 255 252 regKey.SetValue("SplitterDistance", (control as SplitContainer).SplitterDistance); -
Common/FormFind.Designer.cs
r3 r14 1 namespace Common1 namespace Common 2 2 { 3 3 partial class FormFind … … 41 41 // 42 42 this.buttonFindNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 43 this.buttonFindNext.Location = new System.Drawing.Point(4 05, 15);44 this.buttonFindNext.Margin = new System.Windows.Forms.Padding(4 );43 this.buttonFindNext.Location = new System.Drawing.Point(468, 19); 44 this.buttonFindNext.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 45 45 this.buttonFindNext.Name = "buttonFindNext"; 46 this.buttonFindNext.Size = new System.Drawing.Size(1 17, 28);46 this.buttonFindNext.Size = new System.Drawing.Size(132, 35); 47 47 this.buttonFindNext.TabIndex = 4; 48 48 this.buttonFindNext.Text = "Find next"; … … 54 54 this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 55 55 this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 56 this.buttonCancel.Location = new System.Drawing.Point(4 05, 86);57 this.buttonCancel.Margin = new System.Windows.Forms.Padding(4 );56 this.buttonCancel.Location = new System.Drawing.Point(468, 108); 57 this.buttonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 58 58 this.buttonCancel.Name = "buttonCancel"; 59 this.buttonCancel.Size = new System.Drawing.Size(1 16, 28);59 this.buttonCancel.Size = new System.Drawing.Size(130, 35); 60 60 this.buttonCancel.TabIndex = 6; 61 61 this.buttonCancel.Text = "Cancel"; … … 66 66 // 67 67 this.label1.AutoSize = true; 68 this.label1.Location = new System.Drawing.Point(1 6, 21);68 this.label1.Location = new System.Drawing.Point(18, 26); 69 69 this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 70 70 this.label1.Name = "label1"; 71 this.label1.Size = new System.Drawing.Size( 72, 17);71 this.label1.Size = new System.Drawing.Size(82, 20); 72 72 this.label1.TabIndex = 0; 73 73 this.label1.Text = "Find what:"; 74 this.label1.Click += new System.EventHandler(this.label1_Click); 74 75 // 75 76 // checkBoxMatchWholeWordOnly 76 77 // 77 78 this.checkBoxMatchWholeWordOnly.AutoSize = true; 78 this.checkBoxMatchWholeWordOnly.Location = new System.Drawing.Point(2 0, 58);79 this.checkBoxMatchWholeWordOnly.Margin = new System.Windows.Forms.Padding(4 );79 this.checkBoxMatchWholeWordOnly.Location = new System.Drawing.Point(22, 72); 80 this.checkBoxMatchWholeWordOnly.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 80 81 this.checkBoxMatchWholeWordOnly.Name = "checkBoxMatchWholeWordOnly"; 81 this.checkBoxMatchWholeWordOnly.Size = new System.Drawing.Size(1 72, 21);82 this.checkBoxMatchWholeWordOnly.Size = new System.Drawing.Size(193, 24); 82 83 this.checkBoxMatchWholeWordOnly.TabIndex = 2; 83 84 this.checkBoxMatchWholeWordOnly.Text = "Match whole word only"; 84 85 this.checkBoxMatchWholeWordOnly.UseVisualStyleBackColor = true; 86 this.checkBoxMatchWholeWordOnly.CheckedChanged += new System.EventHandler(this.checkBoxMatchWholeWordOnly_CheckedChanged); 85 87 // 86 88 // checkBoxMatchCase 87 89 // 88 90 this.checkBoxMatchCase.AutoSize = true; 89 this.checkBoxMatchCase.Location = new System.Drawing.Point(2 0, 86);90 this.checkBoxMatchCase.Margin = new System.Windows.Forms.Padding(4 );91 this.checkBoxMatchCase.Location = new System.Drawing.Point(22, 108); 92 this.checkBoxMatchCase.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 91 93 this.checkBoxMatchCase.Name = "checkBoxMatchCase"; 92 this.checkBoxMatchCase.Size = new System.Drawing.Size(1 02, 21);94 this.checkBoxMatchCase.Size = new System.Drawing.Size(116, 24); 93 95 this.checkBoxMatchCase.TabIndex = 3; 94 96 this.checkBoxMatchCase.Text = "Match case"; 95 97 this.checkBoxMatchCase.UseVisualStyleBackColor = true; 98 this.checkBoxMatchCase.CheckedChanged += new System.EventHandler(this.checkBoxMatchCase_CheckedChanged); 96 99 // 97 100 // buttonFindPrevious 98 101 // 99 102 this.buttonFindPrevious.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 100 this.buttonFindPrevious.Location = new System.Drawing.Point(4 05, 50);101 this.buttonFindPrevious.Margin = new System.Windows.Forms.Padding(4 );103 this.buttonFindPrevious.Location = new System.Drawing.Point(468, 62); 104 this.buttonFindPrevious.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 102 105 this.buttonFindPrevious.Name = "buttonFindPrevious"; 103 this.buttonFindPrevious.Size = new System.Drawing.Size(1 16, 28);106 this.buttonFindPrevious.Size = new System.Drawing.Size(130, 35); 104 107 this.buttonFindPrevious.TabIndex = 5; 105 108 this.buttonFindPrevious.Text = "Find previous"; … … 112 115 | System.Windows.Forms.AnchorStyles.Right))); 113 116 this.comboBoxWhat.FormattingEnabled = true; 114 this.comboBoxWhat.Location = new System.Drawing.Point(95, 18); 117 this.comboBoxWhat.Location = new System.Drawing.Point(107, 22); 118 this.comboBoxWhat.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 115 119 this.comboBoxWhat.Name = "comboBoxWhat"; 116 this.comboBoxWhat.Size = new System.Drawing.Size( 297, 24);120 this.comboBoxWhat.Size = new System.Drawing.Size(346, 28); 117 121 this.comboBoxWhat.TabIndex = 7; 122 this.comboBoxWhat.SelectedIndexChanged += new System.EventHandler(this.comboBoxWhat_SelectedIndexChanged); 118 123 this.comboBoxWhat.TextChanged += new System.EventHandler(this.textBoxWhat_TextChanged); 119 124 this.comboBoxWhat.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWhat_KeyPress); … … 121 126 // FormFind 122 127 // 123 this.AutoScaleDimensions = new System.Drawing.SizeF( 8F, 16F);128 this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 124 129 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 125 this.ClientSize = new System.Drawing.Size( 537, 126);130 this.ClientSize = new System.Drawing.Size(616, 175); 126 131 this.Controls.Add(this.comboBoxWhat); 127 132 this.Controls.Add(this.buttonFindPrevious); … … 131 136 this.Controls.Add(this.buttonCancel); 132 137 this.Controls.Add(this.buttonFindNext); 133 this.Margin = new System.Windows.Forms.Padding(4 );138 this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 134 139 this.MaximizeBox = false; 135 140 this.MinimizeBox = false; 136 this.MinimumSize = new System.Drawing.Size( 394, 162);141 this.MinimumSize = new System.Drawing.Size(440, 189); 137 142 this.Name = "FormFind"; 138 143 this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; -
Common/FormFind.cs
r13 r14 1 1 using System; 2 using System.Collections.Generic;3 using System.ComponentModel;4 using System.Data;5 2 using System.Drawing; 6 using System.Linq;7 using System.Text;8 using System.Threading.Tasks;9 3 using System.Windows.Forms; 10 4 using Microsoft.Win32; … … 96 90 Theme.UseTheme(this); 97 91 DpiScaling.Apply(this); 98 this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);92 Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 99 93 new FormDimensions().Load(this, Owner); 100 94 comboBoxWhat.Focus(); … … 112 106 { 113 107 SaveToRegistry(); 114 richTextBox. formFind = null;108 richTextBox.FormFind = null; 115 109 new FormDimensions().Save(this, Owner); 116 110 } … … 156 150 comboBoxWhat.SaveToRegistry(); 157 151 } 152 153 private void comboBoxWhat_SelectedIndexChanged(object sender, EventArgs e) 154 { 155 156 } 157 158 private void label1_Click(object sender, EventArgs e) 159 { 160 161 } 162 163 private void checkBoxMatchWholeWordOnly_CheckedChanged(object sender, EventArgs e) 164 { 165 166 } 167 168 private void checkBoxMatchCase_CheckedChanged(object sender, EventArgs e) 169 { 170 171 } 158 172 } 159 173 } -
Common/FormProgress.Designer.cs
r1 r14 40 40 this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 41 41 | System.Windows.Forms.AnchorStyles.Right))); 42 this.progressBar1.Location = new System.Drawing.Point(9, 28); 42 this.progressBar1.Location = new System.Drawing.Point(14, 43); 43 this.progressBar1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 43 44 this.progressBar1.Name = "progressBar1"; 44 this.progressBar1.Size = new System.Drawing.Size( 320, 19);45 this.progressBar1.Size = new System.Drawing.Size(492, 29); 45 46 this.progressBar1.TabIndex = 0; 46 47 // … … 53 54 // 54 55 this.labelOperation.AutoSize = true; 55 this.labelOperation.Location = new System.Drawing.Point(9, 9); 56 this.labelOperation.Location = new System.Drawing.Point(14, 14); 57 this.labelOperation.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 56 58 this.labelOperation.Name = "labelOperation"; 57 this.labelOperation.Size = new System.Drawing.Size( 16, 13);59 this.labelOperation.Size = new System.Drawing.Size(21, 20); 58 60 this.labelOperation.TabIndex = 1; 59 61 this.labelOperation.Text = " "; … … 62 64 // 63 65 this.labelTime.AutoSize = true; 64 this.labelTime.Location = new System.Drawing.Point(9, 53); 66 this.labelTime.Location = new System.Drawing.Point(14, 82); 67 this.labelTime.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); 65 68 this.labelTime.Name = "labelTime"; 66 this.labelTime.Size = new System.Drawing.Size( 16, 13);69 this.labelTime.Size = new System.Drawing.Size(21, 20); 67 70 this.labelTime.TabIndex = 2; 68 71 this.labelTime.Text = " "; … … 70 73 // FormProgress 71 74 // 72 this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F);75 this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); 73 76 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 74 this.ClientSize = new System.Drawing.Size( 338, 75);77 this.ClientSize = new System.Drawing.Size(519, 132); 75 78 this.Controls.Add(this.labelTime); 76 79 this.Controls.Add(this.labelOperation); 77 80 this.Controls.Add(this.progressBar1); 78 this.MinimumSize = new System.Drawing.Size(216, 98); 81 this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 82 this.MinimumSize = new System.Drawing.Size(313, 121); 79 83 this.Name = "FormProgress"; 80 84 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; -
Common/FormProgress.cs
r2 r14 2 2 using System.Collections.Generic; 3 3 using System.ComponentModel; 4 using System.Data;5 4 using System.Drawing; 6 5 using System.Linq; 7 using System.Text;8 6 using System.Windows.Forms; 9 7 … … 12 10 public partial class FormProgress : Form 13 11 { 14 public List<Progress> tasks;15 public DateTime startTime;16 public Progress currentTask;12 public List<Progress> Tasks; 13 public DateTime StartTime; 14 public Progress CurrentTask; 17 15 18 16 public FormProgress() … … 20 18 InitializeComponent(); 21 19 22 tasks = new List<Progress>();23 currentTask = null;20 Tasks = new List<Progress>(); 21 CurrentTask = null; 24 22 } 25 23 … … 27 25 { 28 26 int steps = 10000; 29 int total = tasks.Count * steps;30 int current = 0;31 int index = tasks.IndexOf(currentTask);27 int total = Tasks.Count * steps; 28 int current; 29 int index = Tasks.IndexOf(CurrentTask); 32 30 if (index >= 0) 33 31 { 34 32 current = index * steps; 35 if ( currentTask.total > 0) current += (int)(index + ((double)currentTask.current / currentTask.total) * steps);33 if (CurrentTask.Total > 0) current += (int)(index + ((double)CurrentTask.Current / CurrentTask.Total) * steps); 36 34 } 37 35 else current = 0; … … 40 38 else progressBar1.Value = total; 41 39 progressBar1.Visible = current > 0; 42 if ( currentTask != null) labelOperation.Text = currentTask.operation;40 if (CurrentTask != null) labelOperation.Text = CurrentTask.Operation; 43 41 else labelOperation.Text = ""; 44 42 if ((current > 0) && (total > 0)) 45 43 { 46 TimeSpan timeDiff = TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds / current * (total - current));44 TimeSpan timeDiff = TimeSpan.FromSeconds((DateTime.Now - StartTime).TotalSeconds / current * (total - current)); 47 45 string remaining = timeDiff.ToString(@"hh\:mm\:ss"); 48 if (timeDiff.TotalDays >= 1) remaining = Math.Truncate(timeDiff.TotalDays) .ToString()+ " days " + remaining;49 labelTime.Text = "Remaining time: " + remaining;46 if (timeDiff.TotalDays >= 1) remaining = Math.Truncate(timeDiff.TotalDays) + " days " + remaining; 47 labelTime.Text = @"Remaining time: " + remaining; 50 48 } 51 49 else labelTime.Text = ""; … … 56 54 Theme.UseTheme(this); 57 55 DpiScaling.Apply(this); 58 this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);56 Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 59 57 60 58 timer1_Tick(this, null); … … 65 63 private void FormProgress_FormClosing(object sender, FormClosingEventArgs e) 66 64 { 67 currentTask.terminated = true;65 CurrentTask.Terminated = true; 68 66 timer1.Enabled = false; 69 67 } … … 71 69 private void bg_DoWork(object sender, DoWorkEventArgs e) 72 70 { 73 currentTask.Execute();74 currentTask.completed = !currentTask.terminated;71 CurrentTask.Execute(); 72 CurrentTask.Completed = !CurrentTask.Terminated; 75 73 } 76 74 … … 79 77 if (e.Error != null) 80 78 { 81 currentTask.terminated = true;82 MessageBox.Show(e.Error.Message, "Error in background task", MessageBoxButtons.OK, MessageBoxIcon.Error);79 CurrentTask.Terminated = true; 80 MessageBox.Show(e.Error.Message, @"Error in background task", MessageBoxButtons.OK, MessageBoxIcon.Error); 83 81 } 84 if (! currentTask.terminated)82 if (!CurrentTask.Terminated) 85 83 { 86 int nextIndex = tasks.IndexOf(currentTask) + 1;87 if (nextIndex < tasks.Count)84 int nextIndex = Tasks.IndexOf(CurrentTask) + 1; 85 if (nextIndex < Tasks.Count) 88 86 { 89 currentTask = tasks[nextIndex];87 CurrentTask = Tasks[nextIndex]; 90 88 BackgroundWorker bg = new BackgroundWorker(); 91 bg.DoWork += new DoWorkEventHandler(bg_DoWork);92 bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_DoWorkerCompleted);89 bg.DoWork += bg_DoWork; 90 bg.RunWorkerCompleted += bg_DoWorkerCompleted; 93 91 bg.RunWorkerAsync(); 94 92 } … … 100 98 public void AddTask(string name, Progress.CallbackEventHandler progressCallback) 101 99 { 102 Progress newTask = new Progress(); 103 newTask.terminated = false; 104 newTask.total = 0; 105 newTask.current = 0; 106 newTask.operation = name; 107 newTask.callback += progressCallback; 108 tasks.Add(newTask); 100 Progress newTask = new Progress 101 { 102 Terminated = false, 103 Total = 0, 104 Current = 0, 105 Operation = name 106 }; 107 newTask.Callback += progressCallback; 108 Tasks.Add(newTask); 109 109 } 110 110 111 111 public void StartTask(string name, Progress.CallbackEventHandler progressCallback) 112 112 { 113 tasks.Clear();113 Tasks.Clear(); 114 114 AddTask(name, progressCallback); 115 115 Start(); … … 118 118 public void Start() 119 119 { 120 if ( tasks.Count > 0)120 if (Tasks.Count > 0) 121 121 { 122 startTime = DateTime.Now;123 currentTask = tasks.First();122 StartTime = DateTime.Now; 123 CurrentTask = Tasks.First(); 124 124 BackgroundWorker bg = new BackgroundWorker(); 125 bg.DoWork += new DoWorkEventHandler(bg_DoWork);126 bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_DoWorkerCompleted);125 bg.DoWork += bg_DoWork; 126 bg.RunWorkerCompleted += bg_DoWorkerCompleted; 127 127 bg.RunWorkerAsync(); 128 128 ShowDialog(); … … 133 133 { 134 134 int completed = 0; 135 foreach (var task in tasks)135 foreach (var task in Tasks) 136 136 { 137 if (task. completed) completed += 1;137 if (task.Completed) completed += 1; 138 138 } 139 return completed == tasks.Count;139 return completed == Tasks.Count; 140 140 } 141 141 } … … 143 143 public interface IProgress 144 144 { 145 void SetTotal(int Value);146 void SetProgress(int Value);145 void SetTotal(int value); 146 void SetProgress(int value); 147 147 bool GetTerminated(); 148 148 void SetOperation(string text); … … 152 152 public class Progress : IProgress 153 153 { 154 public int total;155 public int current;156 public bool terminated;157 public bool completed; // If task was not terminated during execution.158 public string operation;154 public int Total; 155 public int Current; 156 public bool Terminated; 157 public bool Completed; // If task was not terminated during execution. 158 public string Operation; 159 159 public delegate void CallbackEventHandler(Progress progress); 160 public event CallbackEventHandler callback; 161 public Exception exception; 160 public event CallbackEventHandler Callback; 162 161 163 public void SetTotal(int Value)162 public void SetTotal(int value) 164 163 { 165 total = Value;164 Total = value; 166 165 } 167 166 168 public void SetProgress(int Value)167 public void SetProgress(int value) 169 168 { 170 current = Value;169 Current = value; 171 170 } 172 171 173 172 public bool GetTerminated() 174 173 { 175 return terminated;174 return Terminated; 176 175 } 177 176 178 177 public void SetOperation(string text) 179 178 { 180 operation = text;179 Operation = text; 181 180 } 182 181 183 182 public void Execute() 184 183 { 185 if (callback != null) callback(this);184 Callback?.Invoke(this); 186 185 } 187 186 } -
Common/ListViewComparer.cs
r1 r14 2 2 using System.Windows.Forms; 3 3 using System.Runtime.InteropServices; 4 using System. Globalization;4 using System.Collections; 5 5 6 6 namespace Common 7 7 { 8 public enum ColumnDataType { String, Integer, DateTime};8 public enum ColumnDataType { String, Integer, DateTime, Decimal, Custom }; 9 9 10 10 // Supports sorting by column in ascending or descending order 11 public class ListViewItemComparer : System.Collections.IComparer11 public class ListViewItemComparer : IComparer 12 12 { 13 private int column = 0;14 private SortOrder order = 0;15 16 public void ColumnClick(int column)13 private int column; 14 private SortOrder order; 15 16 public void ColumnClick(int newColumn) 17 17 { 18 18 // Determine if clicked column is already the column that is being sorted. 19 if ( column == this.column)19 if (newColumn == column) 20 20 { 21 21 // Reverse the current sort direction for this column. … … 32 32 { 33 33 // Set the column number that is to be sorted; default to ascending. 34 this.column = column;34 column = newColumn; 35 35 order = SortOrder.Ascending; 36 36 } 37 37 } 38 38 39 public void SetColumn(int column)40 { 41 this.column = column;42 } 43 44 public void SetOrder(SortOrder order)45 { 46 this.order = order;39 public void SetColumn(int newColumn) 40 { 41 column = newColumn; 42 } 43 44 public void SetOrder(SortOrder newOrder) 45 { 46 order = newOrder; 47 47 } 48 48 … … 53 53 } 54 54 55 public delegate int CompareItemEventHandler(ListViewItem x, ListViewItem y, int column); 56 57 public event CompareItemEventHandler OnCompareItem; 58 55 59 public int Compare(object x, object y) 56 60 { 61 ListViewItem listViewItemX = (ListViewItem)x; 62 ListViewItem listViewItemY = (ListViewItem)y; 63 57 64 int result = 0; 58 if ((column < ((ListViewItem)x).SubItems.Count) && (column < ((ListViewItem)y).SubItems.Count) && (column >= 0)) 59 { 60 ColumnDataType dataType = ColumnDataType.String; 61 62 if (((ListViewItem)x).ListView.Columns[column].Tag != null) 63 dataType = (ColumnDataType)(((ListViewItem)x).ListView.Columns[column].Tag); 64 if (dataType == ColumnDataType.Integer) 65 { 66 int xi = 0; 67 int yi = 0; 68 if (int.TryParse(((ListViewItem)x).SubItems[column].Text, out xi) && 69 int.TryParse(((ListViewItem)y).SubItems[column].Text, out yi)) 70 { 71 if (xi < yi) result = -1; 72 else if (xi > yi) result = 1; 73 else result = 0; 74 } 75 } else 76 if (dataType == ColumnDataType.DateTime) 77 { 78 DateTime xi; 79 DateTime yi; 80 if (DateTime.TryParse(((ListViewItem)x).SubItems[column].Text, out xi) && 81 DateTime.TryParse(((ListViewItem)y).SubItems[column].Text, out yi)) 82 { 83 result = DateTime.Compare(xi, yi); 84 } 85 } 86 else result = String.Compare(((ListViewItem)x).SubItems[column].Text, ((ListViewItem)y).SubItems[column].Text); 87 } 88 if (order == SortOrder.Ascending) 89 { 90 return result; 91 } 92 else if (order == SortOrder.Descending) 93 { 94 return -result; 95 } 96 else 97 { 98 return 0; 65 if (listViewItemX != null && listViewItemY != null) 66 { 67 if (column < listViewItemX.SubItems.Count && column < listViewItemY.SubItems.Count && column >= 0) 68 { 69 ColumnDataType dataType = ColumnDataType.String; 70 71 if (listViewItemX.ListView.Columns[column].Tag != null) 72 { 73 dataType = (ColumnDataType) (listViewItemX.ListView.Columns[column].Tag); 74 } 75 76 if (dataType == ColumnDataType.Integer) 77 { 78 if (int.TryParse(listViewItemX.SubItems[column].Text, out var xi) && 79 int.TryParse(listViewItemY.SubItems[column].Text, out var yi)) 80 { 81 if (xi < yi) result = -1; 82 else if (xi > yi) result = 1; 83 else result = 0; 84 } 85 } 86 else if (dataType == ColumnDataType.Decimal) 87 { 88 if (decimal.TryParse(listViewItemX.SubItems[column].Text, out var xi) && 89 decimal.TryParse(listViewItemY.SubItems[column].Text, out var yi)) 90 { 91 if (xi < yi) result = -1; 92 else if (xi > yi) result = 1; 93 else result = 0; 94 } 95 } 96 else if (dataType == ColumnDataType.DateTime) 97 { 98 if (DateTime.TryParse(listViewItemX.SubItems[column].Text, out var xi) && 99 DateTime.TryParse(listViewItemY.SubItems[column].Text, out var yi)) 100 { 101 result = DateTime.Compare(xi, yi); 102 } 103 } 104 else if (dataType == ColumnDataType.Custom) 105 { 106 if (OnCompareItem != null) 107 { 108 result = OnCompareItem(listViewItemX, listViewItemY, column); 109 } 110 } 111 else 112 result = string.CompareOrdinal(listViewItemX.SubItems[column].Text, 113 listViewItemY.SubItems[column].Text); 114 } 115 else 116 { 117 if (!listViewItemX.Selected && listViewItemY.Selected) result = 1; 118 else if (listViewItemX.Selected && !listViewItemY.Selected) result = -1; 119 } 120 } 121 122 switch (order) 123 { 124 case SortOrder.Ascending: 125 return result; 126 case SortOrder.Descending: 127 return -result; 128 default: 129 return 0; 99 130 } 100 131 } … … 103 134 { 104 135 if (listView.ListViewItemSorter == null) 136 { 105 137 listView.ListViewItemSorter = new ListViewItemComparer(); 106 (listView.ListViewItemSorter as ListViewItemComparer).SetOrder(order); 107 (listView.ListViewItemSorter as ListViewItemComparer).SetColumn(column); 138 } 139 140 ((ListViewItemComparer) listView.ListViewItemSorter).SetOrder(order); 141 ((ListViewItemComparer) listView.ListViewItemSorter).SetColumn(column); 108 142 if ((column != -1) && (order != SortOrder.None)) 109 143 { … … 113 147 listView.ColumnClick += delegate (object sender, ColumnClickEventArgs e) 114 148 { 115 (( sender as ListView).ListViewItemSorter as ListViewItemComparer).ColumnClick(e.Column);116 ( sender as ListView).Sort();117 ( sender as ListView).SetSortIcon(((sender as ListView).ListViewItemSorter as ListViewItemComparer).column, ((sender as ListView).ListViewItemSorter as ListViewItemComparer).order);149 ((ListViewItemComparer) ((ListView) sender).ListViewItemSorter).ColumnClick(e.Column); 150 ((ListView) sender).Sort(); 151 ((ListView) sender).SetSortIcon(((ListViewItemComparer) ((ListView) sender).ListViewItemSorter).column, ((ListViewItemComparer) ((ListView) sender).ListViewItemSorter).order); 118 152 }; 119 153 } … … 181 215 182 216 183 // This method used to set arrow icon217 // This method used to set arrow icon 184 218 public static void SetSortIcon(this ListView listView, int columnIndex, SortOrder order) 185 219 { … … 189 223 { 190 224 IntPtr columnPtr = new IntPtr(columnNumber); 191 LVCOLUMN lvColumn = new LVCOLUMN(); 192 lvColumn.mask = HDI_FORMAT; 225 LVCOLUMN lvColumn = new LVCOLUMN {mask = HDI_FORMAT}; 193 226 194 227 SendMessageLVCOLUMN(columnHeader, HDM_GETITEM, columnPtr, ref lvColumn); 195 228 196 if ( !(order == SortOrder.None)&& columnNumber == columnIndex)229 if (order != SortOrder.None && columnNumber == columnIndex) 197 230 { 198 231 switch (order) 199 232 { 200 case S ystem.Windows.Forms.SortOrder.Ascending:233 case SortOrder.Ascending: 201 234 lvColumn.fmt &= ~HDF_SORTDOWN; 202 235 lvColumn.fmt |= HDF_SORTUP; 203 236 break; 204 case S ystem.Windows.Forms.SortOrder.Descending:237 case SortOrder.Descending: 205 238 lvColumn.fmt &= ~HDF_SORTUP; 206 239 lvColumn.fmt |= HDF_SORTDOWN; -
Common/Prompt.cs
r13 r14 1 1 using System; 2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 2 using System.IO; 6 using System.Threading.Tasks;7 3 using System.Drawing; 8 4 using System.Windows.Forms; … … 25 21 TextBox textBox = new TextBox() { Left = 50, Top = 44, Width = 400, Text = initialValue }; 26 22 textBox.SelectAll(); 27 Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };23 Button confirmation = new Button() { Text = @"Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; 28 24 confirmation.Click += (sender, e) => { prompt.Close(); }; 29 25 prompt.Controls.Add(textBox); … … 31 27 prompt.Controls.Add(textLabel); 32 28 prompt.AcceptButton = confirmation; 33 prompt.Load += delegate (object sender3, EventArgs e3)29 prompt.Load += delegate 34 30 { 35 31 Theme.UseTheme(prompt); … … 71 67 }; 72 68 numericUpDown.Select(0, numericUpDown.Text.Length); 73 Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };69 Button confirmation = new Button() { Text = @"Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; 74 70 confirmation.Click += (sender, e) => { prompt.Close(); }; 75 71 prompt.Controls.Add(numericUpDown); … … 77 73 prompt.Controls.Add(textLabel); 78 74 prompt.AcceptButton = confirmation; 79 prompt.Load += delegate (object sender3, EventArgs e3)75 prompt.Load += delegate 80 76 { 81 77 Theme.UseTheme(prompt); … … 117 113 comboBox.SelectedIndex = 0; 118 114 } 119 Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK };115 Button confirmation = new Button() { Text = @"Ok", Left = 350, Width = 100, Top = 70, DialogResult = DialogResult.OK }; 120 116 confirmation.Click += (sender, e) => { prompt.Close(); }; 121 117 prompt.Controls.Add(comboBox); … … 123 119 prompt.Controls.Add(textLabel); 124 120 prompt.AcceptButton = confirmation; 125 prompt.Load += delegate (object sender3, EventArgs e3)121 prompt.Load += delegate 126 122 { 127 123 Theme.UseTheme(prompt); … … 155 151 Button confirmation = new Button() 156 152 { 157 Text = "Ok",153 Text = @"Ok", 158 154 Left = 350, 159 155 Width = 100, … … 193 189 prompt.Controls.Add(textLabel); 194 190 prompt.AcceptButton = confirmation; 195 prompt.Load += delegate (object sender3, EventArgs e3)191 prompt.Load += delegate 196 192 { 197 193 Theme.UseTheme(prompt); … … 224 220 Label textLabel = new Label() { Left = 50, Top = 20, AutoSize = true, Text = text }; 225 221 RichTextBox textBox = new RichTextBox() { Left = 50, Top = 44, Width = 400, Height = dataSize, Text = initialValue }; 222 textBox.TextChanged += delegate 223 { 224 Theme.UseTheme(prompt); 225 }; 226 226 textBox.SelectAll(); 227 Button confirmation = new Button() { Text = "Ok", Left = 350, Width = 100, Top = dataSize + 70, DialogResult = DialogResult.OK };227 Button confirmation = new Button() { Text = @"Ok", Left = 350, Width = 100, Top = dataSize + 70, DialogResult = DialogResult.OK }; 228 228 confirmation.Click += (sender, e) => { prompt.Close(); }; 229 229 prompt.Controls.Add(textBox); … … 231 231 prompt.Controls.Add(textLabel); 232 232 prompt.AcceptButton = confirmation; 233 prompt.Load += delegate (object sender3, EventArgs e3)233 prompt.Load += delegate 234 234 { 235 235 Theme.UseTheme(prompt); … … 260 260 { 261 261 result = fileName; 262 OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = fileType + " (." + fileExtension + ")|*." +263 fileExtension + "|Any file|*.*", DefaultExt = fileExtension };262 OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = fileType + @"|*." + 263 fileExtension + @"|Any file|*.*", DefaultExt = fileExtension }; 264 264 if (!string.IsNullOrEmpty(fileName)) 265 265 { … … 282 282 { 283 283 result = fileName; 284 SaveFileDialog saveFileDialog = new SaveFileDialog ()285 { 286 Filter = fileType + "|*." +287 fileExtension + "|Any file|*.*",284 SaveFileDialog saveFileDialog = new SaveFileDialog 285 { 286 Filter = fileType + @"|*." + 287 fileExtension + @"|Any file|*.*", 288 288 DefaultExt = fileExtension 289 289 }; -
Common/RecentFiles.cs
r13 r14 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 3 using System.Windows.Forms; 7 4 using Microsoft.Win32; … … 42 39 } 43 40 44 public void LoadFromRegistry(string RegSubKey)41 public void LoadFromRegistry(string regSubKey) 45 42 { 46 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey( RegSubKey);47 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey( RegSubKey);43 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey); 44 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey); 48 45 49 46 int count = (int)regKey.GetValue("Count", 0); … … 56 53 } 57 54 58 public void SaveToRegistry(string RegSubKey)55 public void SaveToRegistry(string regSubKey) 59 56 { 60 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey( RegSubKey, true);61 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey( RegSubKey);57 RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(regSubKey, true); 58 if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(regSubKey); 62 59 63 60 regKey.SetValue("Count", Items.Count); -
Common/Registry.cs
r13 r14 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 1 using Microsoft.Win32; 7 2 … … 17 12 if ((string)value == "True") return true; 18 13 else return false; 14 } 15 else return defaultValue; 16 } 17 18 public static bool? GetValueBoolNullable(this RegistryKey regKey, string name, bool? defaultValue) 19 { 20 object value = regKey.GetValue(name, defaultValue); 21 if (value is string) 22 { 23 if ((string)value == "False") return false; 24 else if ((string)value == "True") return true; 25 else return null; 19 26 } 20 27 else return defaultValue; … … 35 42 } 36 43 44 public static int? GetValueIntNullable(this RegistryKey regKey, string name, int? defaultValue) 45 { 46 object value = regKey.GetValue(name, defaultValue); 47 if (value is int) return (int)value; 48 else if (value is string && (string)value == "") return null; 49 else return defaultValue; 50 } 51 37 52 public static long GetValueLong(this RegistryKey regKey, string name, long defaultValue) 38 53 { 39 54 object value = regKey.GetValue(name, defaultValue); 40 if (value is long) return (long)value;55 if (value is string && long.TryParse(value.ToString(), out long longValue)) return longValue; 41 56 else return defaultValue; 42 57 } … … 54 69 public static void SetValueBool(this RegistryKey regKey, string name, bool value) 55 70 { 56 regKey.SetValue(name, value); 71 if (value) regKey.SetValue(name, "True"); 72 else regKey.SetValue(name, "False"); 57 73 } 58 74 75 public static void SetValueBoolNullable(this RegistryKey regKey, string name, bool? value) 76 { 77 if (value != null) 78 { 79 if (value.Value) regKey.SetValue(name, "True"); 80 else regKey.SetValue(name, "False"); 81 } else regKey.SetValue(name, ""); 82 } 83 59 84 public static void SetValueString(this RegistryKey regKey, string name, string value) 60 85 { … … 66 91 { 67 92 regKey.SetValue(name, value); 93 } 94 95 public static void SetValueIntNullable(this RegistryKey regKey, string name, int? value) 96 { 97 if (value != null) 98 { 99 regKey.SetValue(name, value.Value); 100 } else regKey.SetValue(name, ""); 68 101 } 69 102 -
Common/RichTextBoxEx.Designer.cs
r1 r14 1 namespace Common1 namespace Common 2 2 { 3 3 partial class RichTextBoxEx -
Common/RichTextBoxEx.cs
r13 r14 9 9 public partial class RichTextBoxEx : RichTextBox 10 10 { 11 private bool linksActive = false;11 private bool linksActive; 12 12 public delegate void LinkClickHandler(string link); 13 13 public event LinkClickHandler LinkClick; 14 14 public string Title { get; set; } 15 public Form parentForm;16 public List<LinkMatch> linkMatches;17 public FormFind formFind;18 public string previousRtf;15 public Form ParentForm; 16 public List<LinkMatch> LinkMatches; 17 public FormFind FormFind; 18 public string PreviousRtf; 19 19 private ToolStripMenuItem tsmiUndo; 20 20 private ToolStripMenuItem tsmiRedo; … … 31 31 { 32 32 //InitializeComponent(); 33 KeyDown += new System.Windows.Forms.KeyEventHandler(this.HandleKeyDown);34 KeyUp += new System.Windows.Forms.KeyEventHandler(this.HandleKeyUp);35 MouseClick += new System.Windows.Forms.MouseEventHandler(this.HandleMouseClick);36 MouseLeave += new EventHandler(this.HandleMouseLeave);37 Leave += new EventHandler(this.HandleLeave);38 SelectionChanged += delegate (object sender, EventArgs e)33 KeyDown += HandleKeyDown; 34 KeyUp += HandleKeyUp; 35 MouseClick += HandleMouseClick; 36 MouseLeave += HandleMouseLeave; 37 Leave += HandleLeave; 38 SelectionChanged += delegate 39 39 { 40 40 if (interfaceUpdateEnabled) UpdateInterface(); 41 41 }; 42 42 AddContextMenu(); 43 linkMatches = new List<LinkMatch>();43 LinkMatches = new List<LinkMatch>(); 44 44 } 45 45 … … 54 54 ReadOnly = false; 55 55 interfaceUpdateEnabled = false; 56 previousRtf = Rtf;56 PreviousRtf = Rtf; 57 57 RichTextBoxContext context = new RichTextBoxContext(); 58 58 context.SaveContext(this); 59 59 List<int> linkMatchStart = new List<int>(); 60 foreach (var linkMatch in linkMatches) 60 foreach (var linkMatch in LinkMatches) 61 { 61 62 linkMatchStart.Add(-2); 63 } 64 62 65 List<string> linkMatchStartString = new List<string>(); 63 foreach (var linkMatch in linkMatches)64 linkMatchStartString.Add(linkMatch. startString.ToLowerInvariant());66 foreach (var linkMatch in LinkMatches) 67 linkMatchStartString.Add(linkMatch.StartString.ToLowerInvariant()); 65 68 66 69 string content = richTextBox.Text; … … 71 74 72 75 int contentStart = 0; 73 int selectionStart = 0;74 76 do 75 77 { … … 79 81 { 80 82 int i = 0; 81 foreach (var linkMatch in linkMatches)83 foreach (var linkMatch in LinkMatches) 82 84 { 83 85 if ((linkMatchStart[i] < contentStart) && (linkMatchStart[i] != -1)) 84 86 { 85 if (linkMatch. caseSensitive)87 if (linkMatch.CaseSensitive) 86 88 { 87 linkMatchStart[i] = content.IndexOf(linkMatch. startString, contentStart, StringComparison.Ordinal);89 linkMatchStart[i] = content.IndexOf(linkMatch.StartString, contentStart, StringComparison.Ordinal); 88 90 } else 89 91 { … … 103 105 104 106 int index = firstIndex; 105 string startString = firstMatch. startString;107 string startString = firstMatch.StartString; 106 108 107 109 int linkLength = startString.Length; 108 selectionStart = index; 109 110 string linkTextAfter = ""; 111 if (firstMatch.ExecuteMatch(content, index + startString.Length, out linkTextAfter)) 112 { 113 if ((firstMatch.startString != "") || ((firstMatch.startString == "") && (linkTextAfter.Length == 5) && 110 var selectionStart = index; 111 112 if (firstMatch.ExecuteMatch(content, index + startString.Length, out var linkTextAfter)) 113 { 114 if ((firstMatch.StartString != "") || ((firstMatch.StartString == "") && (linkTextAfter.Length == 5) && 114 115 ((index < 1) || 115 116 ((index >= 1) && ((content[index - 1] == ' ') || (content[index - 1] == '\n')))) … … 175 176 public void UndoUnknownActions() 176 177 { 178 int i = 0; 177 179 while (CanUndo && (UndoActionId == UndoNameId.Unknown)) 178 180 { 179 181 Undo(); 180 } 181 } 182 183 private void HideRichTextBoxLinks(RichTextBox richTextBox) 182 i++; 183 if (i > 1000) break; 184 } 185 } 186 187 private void HideRichTextBoxLinks() 184 188 { 185 189 bool lastReadOnlyState = ReadOnly; … … 188 192 RichTextBoxContext context = new RichTextBoxContext(); 189 193 context.SaveContext(this); 190 Rtf = previousRtf;194 Rtf = PreviousRtf; 191 195 UndoUnknownActions(); 192 196 … … 219 223 if ((e.KeyCode == Keys.ControlKey) && linksActive) 220 224 { 221 HideRichTextBoxLinks( this);225 HideRichTextBoxLinks(); 222 226 linksActive = false; 223 227 } … … 228 232 if ((e.Button == MouseButtons.Left) && linksActive) 229 233 { 230 int linkStart = 0;231 int linkEnd = 0;234 int linkStart; 235 int linkEnd; 232 236 int mousePointerCharIndex = GetCharIndexFromPosition(e.Location); 233 237 SelectionStart = mousePointerCharIndex; … … 238 242 { 239 243 SelectionStart -= 1; 240 continue;241 244 } 242 245 else … … 257 260 { 258 261 SelectionStart += 1; 259 continue;260 262 } 261 263 else … … 273 275 if (link != "") 274 276 { 275 foreach (var linkMatch in linkMatches)277 foreach (var linkMatch in LinkMatches) 276 278 { 277 if ((link.Length >= linkMatch. startString.Length) && (278 (linkMatch. caseSensitive && (link.Substring(0, linkMatch.startString.Length) == linkMatch.startString)) ||279 (!linkMatch. caseSensitive && (link.ToLowerInvariant().Substring(0, linkMatch.startString.Length) == linkMatch.startString.ToLower()))))279 if ((link.Length >= linkMatch.StartString.Length) && ( 280 (linkMatch.CaseSensitive && (link.Substring(0, linkMatch.StartString.Length) == linkMatch.StartString)) || 281 (!linkMatch.CaseSensitive && (link.ToLowerInvariant().Substring(0, linkMatch.StartString.Length) == linkMatch.StartString.ToLower())))) 280 282 { 281 string linkNumber = link.Substring(linkMatch. startString.Length).Trim(new char[] { ' ', '#' });283 string linkNumber = link.Substring(linkMatch.StartString.Length).Trim(new char[] { ' ', '#' }); 282 284 if (int.TryParse(linkNumber, out int number)) 283 285 { … … 287 289 } 288 290 } 289 if (LinkClick != null) LinkClick(link); 290 HideRichTextBoxLinks(this); 291 292 LinkClick?.Invoke(link); 293 HideRichTextBoxLinks(); 291 294 linksActive = false; 292 295 } … … 297 300 public void ShowInWindow() 298 301 { 299 Form textForm = new Form ()302 Form textForm = new Form 300 303 { 301 304 Name = "FormRichTextBox", … … 304 307 FormBorderStyle = FormBorderStyle.Sizable, 305 308 Text = Title, 306 Font = new Font( this.Font.FontFamily, this.Font.Size),309 Font = new Font(Font.FontFamily, Font.Size), 307 310 StartPosition = FormStartPosition.CenterScreen, 311 Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath), 308 312 }; 309 textForm.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); 310 RichTextBoxEx richTextBox = new RichTextBoxEx(); 311 richTextBox.parentForm = textForm; 312 richTextBox.Dock = DockStyle.Fill; 313 richTextBox.Text = this.Text; 314 richTextBox.Title = this.Title; 315 richTextBox.linkMatches = this.linkMatches; 316 richTextBox.ReadOnly = this.ReadOnly; 317 richTextBox.LinkClick = delegate (string linkText) 318 { 319 if (this.LinkClick != null) this.LinkClick.Invoke(linkText); 313 RichTextBoxEx richTextBox = new RichTextBoxEx 314 { 315 ParentForm = textForm, 316 Dock = DockStyle.Fill, 317 Text = Text, 318 Title = Title, 319 LinkMatches = LinkMatches, 320 ReadOnly = ReadOnly, 321 LinkClick = delegate(string linkText) { LinkClick?.Invoke(linkText); } 320 322 }; 321 323 textForm.Controls.Add(richTextBox); 322 textForm.Load += delegate (object sender3, EventArgs e3)324 textForm.Load += delegate 323 325 { 324 326 Theme.UseTheme(textForm); 325 327 DpiScaling.Apply(textForm); 326 new FormDimensions().Load(textForm, parentForm);328 new FormDimensions().Load(textForm, ParentForm); 327 329 richTextBox.ClearUndo(); 328 330 }; 329 textForm.FormClosing += delegate (object sender2, FormClosingEventArgs e2)330 { 331 new FormDimensions().Save(textForm, parentForm);331 textForm.FormClosing += delegate 332 { 333 new FormDimensions().Save(textForm, ParentForm); 332 334 }; 333 335 textForm.Show(); … … 336 338 private void UpdateInterface() 337 339 { 338 tsmiUndo.Enabled = CanUndo && ! this.ReadOnly;339 tsmiRedo.Enabled = CanRedo && ! this.ReadOnly;340 tsmiCut.Enabled = (SelectionLength != 0) && ! this.ReadOnly;340 tsmiUndo.Enabled = CanUndo && !ReadOnly; 341 tsmiRedo.Enabled = CanRedo && !ReadOnly; 342 tsmiCut.Enabled = (SelectionLength != 0) && !ReadOnly; 341 343 tsmiCopy.Enabled = SelectionLength != 0; 342 tsmiPaste.Enabled = Clipboard.ContainsText() && ! this.ReadOnly;343 tsmiDelete.Enabled = (SelectionLength != 0) && ! this.ReadOnly;344 tsmiPaste.Enabled = Clipboard.ContainsText() && !ReadOnly; 345 tsmiDelete.Enabled = (SelectionLength != 0) && !ReadOnly; 344 346 tsmiSelectAll.Enabled = (TextLength > 0) && (SelectionLength < TextLength); 345 347 } … … 349 351 if (linksActive) 350 352 { 351 HideRichTextBoxLinks( this);353 HideRichTextBoxLinks(); 352 354 linksActive = false; 353 355 } … … 435 437 tsmiFind.Click += (sender, e) => { 436 438 HideLinks(); 437 if ( formFind == null)438 { 439 formFind = new FormFind();440 formFind.richTextBox = this;441 formFind.Owner = parentForm;442 } 443 formFind.Show();444 formFind.BringToFront();439 if (FormFind == null) 440 { 441 FormFind = new FormFind(); 442 FormFind.richTextBox = this; 443 FormFind.Owner = ParentForm; 444 } 445 FormFind.Show(); 446 FormFind.BringToFront(); 445 447 }; 446 448 tsmiFind.ShortcutKeys = Keys.F | Keys.Control; … … 514 516 public class LinkMatch 515 517 { 516 public string startString;517 public bool caseSensitive;518 public string StartString; 519 public bool CaseSensitive; 518 520 public delegate bool MatchHandler(string inContent, int startIndex, out string outContent); 519 521 public delegate void LinkActionHandler(int number); … … 523 525 public LinkMatch(string startString, MatchHandler matchHandler, LinkActionHandler action) 524 526 { 525 this.startString = startString;527 StartString = startString; 526 528 Match = matchHandler; 527 529 LinkAction = action; … … 551 553 552 554 // Try to connect to following number 553 string number;554 555 numberStart = startIndex; 555 556 while (((content.Length - numberStart) >= 1) && ((content[numberStart] == ' ') || (content[numberStart] == '#'))) … … 564 565 i++; 565 566 } 566 number = content.Substring(numberStart, i);567 var number = content.Substring(numberStart, i); 567 568 568 569 if (int.TryParse(number, out int intNumber)) -
Common/RichTextBoxEx.resx
r1 r14 1 <?xml version="1.0" encoding="utf-8"?>1 <?xml version="1.0" encoding="utf-8"?> 2 2 <root> 3 3 <!-- -
Common/Table.cs
r13 r14 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics.Eventing.Reader;4 3 using System.Linq; 4 using System.Windows.Forms; 5 5 using System.Text; 6 using System.Threading.Tasks;7 6 8 7 namespace Common 9 8 { 10 public class Row11 {12 public List<string> cells = new List<string>();13 14 public void AddCell(string text)15 {16 cells.Add(text);17 }18 }19 20 9 public enum OutputFormat 21 10 { 22 11 Excel, 23 12 Plain, 24 Csv 13 Csv, 14 Html, 15 ListView 25 16 }; 17 18 public class Row 19 { 20 public List<string> Cells = new List<string>(); 21 22 public void AddCell(string text) 23 { 24 Cells.Add(text); 25 } 26 } 26 27 27 28 public class Table 28 29 { 29 public List<Row> rows = new List<Row>();30 public List<Row> Rows = new List<Row>(); 30 31 31 32 public void Clear() 32 33 { 33 rows.Clear();34 Rows.Clear(); 34 35 } 35 36 … … 37 38 { 38 39 Row row = new Row(); 39 rows.Add(row);40 Rows.Add(row); 40 41 return row; 41 42 } … … 44 45 { 45 46 StringBuilder output = new StringBuilder(); 46 foreach (var row in rows)47 foreach (var row in Rows) 47 48 { 48 output.AppendLine(string.Join("\t", row. cells));49 output.AppendLine(string.Join("\t", row.Cells)); 49 50 } 50 51 return output.ToString(); … … 54 55 { 55 56 StringBuilder output = new StringBuilder(); 56 foreach (var row in rows)57 foreach (var row in Rows) 57 58 { 58 output.AppendLine(string.Join(Environment.NewLine, row. cells));59 output.AppendLine(string.Join(Environment.NewLine, row.Cells)); 59 60 output.AppendLine(); 60 61 output.AppendLine("==========================="); … … 67 68 { 68 69 StringBuilder output = new StringBuilder(); 69 foreach (var row in rows)70 foreach (var row in Rows) 70 71 { 71 output.AppendLine(string.Join(",", row. cells.Select(x => "\"" + x + "\"")));72 output.AppendLine(string.Join(",", row.Cells.Select(x => "\"" + x + "\""))); 72 73 } 73 74 return output.ToString(); 75 } 76 77 public string GetOutputHtml() 78 { 79 StringBuilder output = new StringBuilder(); 80 output.AppendLine("<table border=\"1\">"); 81 foreach (var row in Rows) 82 { 83 output.AppendLine("<tr><td>" + string.Join("</td><td>", row.Cells.Select(x => x.Replace(Environment.NewLine, "<br/>"))) + "</td></tr>"); 84 } 85 output.AppendLine("</table>"); 86 return output.ToString(); 87 } 88 89 public void GetOutputListView(ListView listView) 90 { 91 foreach (var row in Rows) 92 { 93 if (listView.Columns.Count == 0 && row.Cells.Count > 0) 94 { 95 while (listView.Columns.Count < row.Cells.Count) 96 listView.Columns.Add(row.Cells[listView.Columns.Count]); 97 } 98 else 99 { 100 while (listView.Columns.Count < row.Cells.Count) 101 listView.Columns.Add(""); 102 ListViewItem item = new ListViewItem(); 103 int i = 0; 104 foreach (var cell in row.Cells) 105 { 106 if (i == 0) item.Text = cell; 107 else item.SubItems.Add(cell); 108 i++; 109 } 110 listView.Items.Add(item); 111 } 112 } 113 114 foreach (ColumnHeader column in listView.Columns) 115 { 116 column.Width = listView.Width / listView.Columns.Count; 117 } 74 118 } 75 119 … … 79 123 else if (outputFormat == OutputFormat.Plain) return GetOutputPlain(); 80 124 else if (outputFormat == OutputFormat.Csv) return GetOutputCsv(); 125 else if (outputFormat == OutputFormat.Html) return GetOutputHtml(); 81 126 else return ""; 82 127 } -
Common/Theme.cs
r13 r14 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 using System.Threading.Tasks;6 1 using System.Windows.Forms; 7 2 using System.Drawing; 8 3 using System.ComponentModel; 9 using System.IO;10 4 11 5 namespace Common … … 14 8 { 15 9 public delegate void ApplyThemeHandler(Component component); 16 static public event ApplyThemeHandler OnApplyTheme = null;17 static public Color ColorWindow;18 static public Color ColorWindowText;19 static public Color ColorControl;20 static public Color ColorControlText;21 static public Color ColorControlSelected;22 static public bool used = false;23 static private stringname;24 static public string Name25 { 26 get { return name; }10 public static event ApplyThemeHandler OnApplyTheme; 11 public static Color ColorWindow; 12 public static Color ColorWindowText; 13 public static Color ColorControl; 14 public static Color ColorControlText; 15 public static Color ColorControlSelected; 16 public static bool Used; 17 private static string _name; 18 public static string Name 19 { 20 get => _name; 27 21 set 28 22 { 29 name = value; 30 if (value == "Dark") 31 { 32 ColorWindow = Color.FromArgb(0x20, 0x20, 0x20); 33 ColorWindowText = Color.White; 34 ColorControl = Color.FromArgb(0x40, 0x40, 0x40); 35 ColorControlText = Color.White; 36 ColorControlSelected = Color.FromArgb(255, 96, 125, 155); 37 } 38 else 39 if (value == "Light") 40 { 41 ColorWindow = Color.White; 42 ColorWindowText = Color.Black; 43 ColorControl = Color.FromArgb(0xe0, 0xe0, 0xe0); 44 ColorControlText = Color.Black; 45 ColorControlSelected = Color.FromArgb(255, 196, 225, 255); 46 } 47 else 48 { 49 name = "System"; 50 ColorWindow = Color.FromKnownColor(KnownColor.Window); 51 ColorWindowText = Color.FromKnownColor(KnownColor.WindowText); 52 ColorControl = Color.FromKnownColor(KnownColor.Control); 53 ColorControlText = Color.FromKnownColor(KnownColor.ControlText); 54 ColorControlSelected = Color.FromArgb(255, 196, 225, 255); 55 } 23 _name = value; 24 switch (value) 25 { 26 case "Dark": 27 ColorWindow = Color.FromArgb(0x20, 0x20, 0x20); 28 ColorWindowText = Color.White; 29 ColorControl = Color.FromArgb(0x40, 0x40, 0x40); 30 ColorControlText = Color.White; 31 ColorControlSelected = Color.FromArgb(255, 96, 125, 155); 32 break; 33 case "Light": 34 ColorWindow = Color.White; 35 ColorWindowText = Color.Black; 36 ColorControl = Color.FromArgb(0xe0, 0xe0, 0xe0); 37 ColorControlText = Color.Black; 38 ColorControlSelected = Color.FromArgb(255, 196, 225, 255); 39 break; 40 default: 41 _name = "System"; 42 ColorWindow = Color.FromKnownColor(KnownColor.Window); 43 ColorWindowText = Color.FromKnownColor(KnownColor.WindowText); 44 ColorControl = Color.FromKnownColor(KnownColor.Control); 45 ColorControlText = Color.FromKnownColor(KnownColor.ControlText); 46 ColorControlSelected = Color.FromArgb(255, 196, 225, 255); 47 break; 48 } 56 49 } 57 50 } … … 72 65 // Exchange dark with light colors and vice versa 73 66 if (color == Color.DarkBlue) color = Color.LightBlue; 74 if (color == Color.LightBlue) color = Color.DarkBlue;67 else if (color == Color.LightBlue) color = Color.DarkBlue; 75 68 else if (color == Color.DarkGreen) color = Color.LightGreen; 76 69 else if (color == Color.LightGreen) color = Color.DarkGreen; … … 97 90 public static void ApplyTheme(Component component) 98 91 { 99 if (component is Control )100 { 101 foreach (Control child in (component as Control).Controls)92 if (component is Control control) 93 { 94 foreach (Control child in control.Controls) 102 95 { 103 96 ApplyTheme(child); 104 97 } 105 98 106 if ((co mponent is TextBox) || (component is NumericUpDown) || (component is ComboBox) || (componentis RichTextBox)107 || (co mponentis ListView))108 { 109 (component as Control).BackColor = ColorWindow;110 (component as Control).ForeColor = ColorWindowText;99 if ((control is TextBox) || (control is NumericUpDown) || (control is ComboBox) || (control is RichTextBox) 100 || (control is ListView)) 101 { 102 control.BackColor = ColorWindow; 103 control.ForeColor = ColorWindowText; 111 104 } 112 105 else 113 106 { 114 (component as Control).BackColor = ColorControl; 115 (component as Control).ForeColor = ColorControlText; 116 } 117 if ((component as Control).ContextMenuStrip != null) 118 { 119 ApplyTheme((component as Control).ContextMenuStrip); 120 } 121 } 122 123 if ((component is Button) && (Name == "System")) 124 { 125 (component as Button).UseVisualStyleBackColor = true; 126 } else 127 if (component is LinkLabel) 128 { 129 (component as LinkLabel).LinkColor = ColorControlText; 130 (component as LinkLabel).ActiveLinkColor = ColorControlText; 131 (component as LinkLabel).VisitedLinkColor = ColorControlText; 132 } else 133 if (component is TabControl) 134 { 135 foreach (TabPage tabPage in (component as TabControl).TabPages) 107 control.BackColor = ColorControl; 108 control.ForeColor = ColorControlText; 109 } 110 if (control.ContextMenuStrip != null) 111 { 112 ApplyTheme(control.ContextMenuStrip); 113 } 114 } 115 116 if (component is SplitButton splitButton) 117 { 118 ApplyTheme(splitButton.Menu); 119 } 120 if ((component is Button button) && (Name == "System")) 121 { 122 button.UseVisualStyleBackColor = true; 123 } else 124 if (component is LinkLabel linkLabel) 125 { 126 linkLabel.LinkColor = ColorControlText; 127 linkLabel.ActiveLinkColor = ColorControlText; 128 linkLabel.VisitedLinkColor = ColorControlText; 129 } else 130 if (component is TabControl tabControl) 131 { 132 foreach (TabPage tabPage in tabControl.TabPages) 136 133 { 137 134 ApplyTheme(tabPage); 138 135 } 139 136 } else 140 if (component is ToolStrip )141 { 142 (component as ToolStrip).RenderMode = ToolStripRenderMode.Professional;143 (component as ToolStrip).Renderer = new ToolStripProfessionalRenderer(new ThemeColorTable());144 foreach (ToolStripItem item in (component as ToolStrip).Items)145 { 146 if (item is ToolStripMenuItem )137 if (component is ToolStrip toolStrip) 138 { 139 toolStrip.RenderMode = ToolStripRenderMode.Professional; 140 toolStrip.Renderer = new ToolStripProfessionalRenderer(new ThemeColorTable()); 141 foreach (ToolStripItem item in toolStrip.Items) 142 { 143 if (item is ToolStripMenuItem toolStripMenuItem) 147 144 { 148 149 if ((item as ToolStripMenuItem).HasDropDownItems)150 foreach (ToolStripItem dropDownItem in (item as ToolStripMenuItem).DropDownItems)145 if (toolStripMenuItem.DropDownItems.Count > 0) 146 { 147 foreach (ToolStripItem dropDownItem in toolStripMenuItem.DropDownItems) 151 148 { 152 149 ApplyTheme(dropDownItem); 153 150 } 151 } 154 152 } 155 153 ApplyTheme(item); 156 154 } 157 155 } else 158 if (component is ToolStripItem) 159 { 160 (component as ToolStripItem).ForeColor = ColorControlText; 161 (component as ToolStripItem).BackColor = ColorControl; 162 } else 163 if (component is DataGridView) 164 { 165 (component as DataGridView).BackgroundColor = ColorWindow; 166 (component as DataGridView).DefaultCellStyle.BackColor = ColorWindow; 167 (component as DataGridView).DefaultCellStyle.ForeColor = ColorWindowText; 168 (component as DataGridView).ColumnHeadersDefaultCellStyle.BackColor = ColorWindow; 169 (component as DataGridView).ColumnHeadersDefaultCellStyle.ForeColor = ColorWindowText; 170 } else 171 if (component is RichTextBox) 172 { 173 (component as RichTextBox).SelectAll(); 174 (component as RichTextBox).SelectionColor = ColorWindowText; 175 (component as RichTextBox).SelectionLength = 0; 176 } else 177 178 if (OnApplyTheme != null) OnApplyTheme(component); 156 if (component is ToolStripItem toolStripItem) 157 { 158 toolStripItem.ForeColor = ColorControlText; 159 toolStripItem.BackColor = ColorControl; 160 if (toolStripItem is ToolStripMenuItem toolStripMenuItem) 161 { 162 if (toolStripMenuItem.DropDownItems.Count > 0) 163 { 164 foreach (ToolStripItem dropDownItem in toolStripMenuItem.DropDownItems) 165 { 166 ApplyTheme(dropDownItem); 167 } 168 } 169 } 170 } else 171 if (component is DataGridView dataGridView) 172 { 173 dataGridView.BackgroundColor = ColorWindow; 174 dataGridView.DefaultCellStyle.BackColor = ColorWindow; 175 dataGridView.DefaultCellStyle.ForeColor = ColorWindowText; 176 dataGridView.ColumnHeadersDefaultCellStyle.BackColor = ColorWindow; 177 dataGridView.ColumnHeadersDefaultCellStyle.ForeColor = ColorWindowText; 178 } else 179 if (component is RichTextBox richTextBox) 180 { 181 richTextBox.SelectAll(); 182 richTextBox.SelectionColor = ColorWindowText; 183 richTextBox.SelectionLength = 0; 184 } else 185 { 186 OnApplyTheme?.Invoke(component); 187 } 179 188 } 180 189 181 190 public static void UseTheme(Form form) 182 191 { 183 if (! used && (name == "System")) return;192 if (!Used && (_name == "System")) return; 184 193 ApplyTheme(form); 185 used = true;194 Used = true; 186 195 } 187 196 } … … 189 198 public class ThemeColorTable : ProfessionalColorTable 190 199 { 191 public override Color MenuStripGradientBegin 192 { 193 get 194 { 195 return Theme.ColorControl; 196 } 197 } 198 199 public override Color MenuStripGradientEnd 200 { 201 get 202 { 203 return Theme.ColorControl; 204 } 205 } 206 207 public override Color ToolStripContentPanelGradientBegin 208 { 209 get 210 { 211 return Theme.ColorControl; 212 } 213 } 214 215 public override Color ToolStripContentPanelGradientEnd 216 { 217 get 218 { 219 return Theme.ColorControl; 220 } 221 } 222 223 public override Color ToolStripDropDownBackground 224 { 225 get 226 { 227 return Theme.ColorControl; 228 } 229 } 230 231 public override Color ToolStripGradientBegin 232 { 233 get 234 { 235 return Theme.ColorControl; 236 } 237 } 238 239 public override Color ToolStripGradientMiddle 240 { 241 get 242 { 243 return Theme.ColorControl; 244 } 245 } 246 247 public override Color ToolStripGradientEnd 248 { 249 get 250 { 251 return Theme.ColorControl; 252 } 253 } 254 255 public override Color MenuItemSelected 256 { 257 get 258 { 259 return Theme.ColorControlSelected; 260 } 261 } 262 263 public override Color MenuItemSelectedGradientBegin 264 { 265 get 266 { 267 return Theme.ColorControlSelected; 268 } 269 } 270 271 public override Color MenuItemSelectedGradientEnd 272 { 273 get 274 { 275 return Theme.ColorControlSelected; 276 } 277 } 278 279 public override Color ImageMarginGradientBegin 280 { 281 get 282 { 283 return Theme.ColorControl; 284 } 285 } 286 287 public override Color ImageMarginGradientMiddle 288 { 289 get 290 { 291 return Theme.ColorControl; 292 } 293 } 294 295 public override Color ImageMarginGradientEnd 296 { 297 get 298 { 299 return Theme.ColorControl; 300 } 301 } 302 303 public override Color MenuItemPressedGradientBegin 304 { 305 get 306 { 307 return Theme.ColorControlSelected; 308 } 309 } 310 311 public override Color MenuItemPressedGradientMiddle 312 { 313 get 314 { 315 return Theme.ColorControlSelected; 316 } 317 } 318 319 public override Color MenuItemPressedGradientEnd 320 { 321 get 322 { 323 return Theme.ColorControlSelected; 324 } 325 } 200 public override Color MenuStripGradientBegin => Theme.ColorControl; 201 public override Color MenuStripGradientEnd => Theme.ColorControl; 202 public override Color ToolStripContentPanelGradientBegin => Theme.ColorControl; 203 public override Color ToolStripContentPanelGradientEnd => Theme.ColorControl; 204 public override Color ToolStripDropDownBackground => Theme.ColorControl; 205 public override Color ToolStripGradientBegin => Theme.ColorControl; 206 public override Color ToolStripGradientMiddle => Theme.ColorControl; 207 public override Color ToolStripGradientEnd => Theme.ColorControl; 208 public override Color MenuItemSelected => Theme.ColorControlSelected; 209 public override Color MenuItemSelectedGradientBegin => Theme.ColorControlSelected; 210 public override Color MenuItemSelectedGradientEnd => Theme.ColorControlSelected; 211 public override Color ImageMarginGradientBegin => Theme.ColorControl; 212 public override Color ImageMarginGradientMiddle => Theme.ColorControl; 213 public override Color ImageMarginGradientEnd => Theme.ColorControl; 214 public override Color MenuItemPressedGradientBegin => Theme.ColorControlSelected; 215 public override Color MenuItemPressedGradientMiddle => Theme.ColorControlSelected; 216 public override Color MenuItemPressedGradientEnd => Theme.ColorControlSelected; 326 217 } 327 218 }
Note:
See TracChangeset
for help on using the changeset viewer.