Changeset 14


Ignore:
Timestamp:
Aug 2, 2022, 11:46:25 AM (21 months ago)
Author:
chronos
Message:
  • Modified: Various improvements.
Location:
Common
Files:
4 added
19 edited

Legend:

Unmodified
Added
Removed
  • Common/ComboBoxEx.Designer.cs

    r3 r14  
    1 namespace Common
     1namespace Common
    22{
    33    partial class ComboBoxEx
  • Common/ComboBoxEx.cs

    r13 r14  
    1 using System;
    21using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Diagnostics;
    52using System.Linq;
    6 using System.Text;
    73using System.Windows.Forms;
    84using Microsoft.Win32;
    9 using Common;
    105
    116namespace Common
     
    2722            if (Text.Trim() != "")
    2823            {
     24                BeginUpdate();
    2925                string previousText = Text;
    3026                int index = Items.IndexOf(Text);
     
    3531                while (Items.Count > maxHistoryCount)
    3632                    Items.RemoveAt(Items.Count - 1);
     33                EndUpdate();
    3734            }
    3835        }
  • Common/CsvExport.cs

    r1 r14  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    42using System.Text;
    53using System.IO;
    64using System.Windows.Forms;
    7 using System.Threading.Tasks;
    85
    96namespace Common
     
    118    class CsvExport
    129    {
    13         public void ListViewToCSV(ListView listView, string filePath, bool includeHidden)
     10        public void ListViewToCsv(ListView listView, string filePath, bool includeHidden)
    1411        {
    1512            // Make header string
    1613            StringBuilder result = new StringBuilder();
    17             WriteCSVRow(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);
    1815
    1916            // Export data rows
    2017            foreach (ListViewItem listItem in listView.Items)
    21                 WriteCSVRow(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);
    2219
    2320            File.WriteAllText(filePath, result.ToString());
    2421        }
    2522
    26         public void DataGridViewToCSV(DataGridView dataGridView, string filePath, bool includeHidden)
     23        public void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden)
    2724        {
    2825            // Make header string
    2926            StringBuilder result = new StringBuilder();
    30             WriteCSVRow(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);
    3128
    3229            // Export data rows
    3330            foreach (DataGridViewRow row in dataGridView.Rows)
    34                 WriteCSVRow(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());
    3532
    3633            File.WriteAllText(filePath, result.ToString());
    3734        }       
    3835
    39         private void WriteCSVRow(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)
    4037        {
    4138            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;
    61using System.Windows.Forms;
    72using System.Drawing;
    83using System.ComponentModel;
     4using Microsoft.Win32;
    95
    106namespace Common
     
    128    class DpiScaling
    139    {
    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;       
    1814
    1915        public static void ApplyToComponent(Component component)
     
    2925            {
    3026                //(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));
    3329/*                foreach (ToolStripItem item in (component as ToolStrip).Items)
    3430                {
     
    5854            if (component is MenuStrip)
    5955            {
    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);
    6258            }
    6359            if (component is TabControl)
     
    7066            if (component is ToolStripItem)
    7167            {
    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);
    7470            }
    7571        }
     
    7773        public static void Apply(Form form)
    7874        {
    79             if (useCustomDpi) changed = true;
    80             if (systemDpi == 0)
     75            if (UseCustomDpi) _changed = true;
     76            if (SystemDpi == 0)
    8177            {
    8278                Graphics graphics = form.CreateGraphics();
    83                 systemDpi = graphics.DpiX;
     79                SystemDpi = graphics.DpiX;
    8480            }
    85             if (useCustomDpi || changed)
     81            if (UseCustomDpi || _changed)
    8682            {
    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);
    8985                ApplyToComponent(form);
    9086            }           
    9187        }
    9288
    93         public static float Scale(float size)
     89        public static float Scale(float size, float baseDpi = 96F)
    9490        {
    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
    96100            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);
    97121        }
    98122    }
  • Common/FileExt.cs

    r5 r14  
    2323            } else File.WriteAllText(fileName, content);
    2424        }
     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        }
    2544    }
    2645}
  • Common/FormDimensions.cs

    r12 r14  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    52using System.Drawing;
    63using System.Windows.Forms;
     
    129    class FormDimensions
    1310    {
    14         public Form form;
     11        public Form Form;
    1512        public string RegSubKey;
    16         public FormWindowState defaultFormWindowState = FormWindowState.Normal;
     13        public FormWindowState DefaultFormWindowState = FormWindowState.Normal;
    1714
    1815        [DllImport("user32.dll")]
     
    7370        public void Load(Form form, Form parentForm = null)
    7471        {
    75             this.form = form;
     72            this.Form = form;
    7673            RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name);
    7774            if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name);
     
    103100                (int)regKey.GetValue("RestoreBoundsWidth" + name, restoreBounds.Width),
    104101                (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);
    106103            if (parentForm != null)
    107104            {
     
    150147        public void Save(Form form, Form parentForm = null)
    151148        {
    152             this.form = form;
     149            this.Form = form;
    153150            RegistryKey regKey = Application.UserAppDataRegistry.OpenSubKey(RegSubKey + "\\" + form.Name, true);
    154151            if (regKey == null) regKey = Application.UserAppDataRegistry.CreateSubKey(RegSubKey + "\\" + form.Name);
     
    191188            if (control is ListView)
    192189            {
    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);
    195192
    196193                for (int I = 0; I < (control as ListView).Columns.Count; I++)
     
    202199            if (control is DataGridView)
    203200            {
    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);
    206203
    207204                for (int I = 0; I < (control as DataGridView).Columns.Count; I++)
     
    213210            if (control is SplitContainer)
    214211            {
    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);
    217214
    218215                if (regKey.GetValue("SplitterDistance") != null)
     
    230227            if (control is ListView)
    231228            {
    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);
    234231
    235232                for (int I = 0; I < (control as ListView).Columns.Count; I++)
     
    240237            if (control is DataGridView)
    241238            {
    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);
    244241
    245242                for (int I = 0; I < (control as DataGridView).Columns.Count; I++)
     
    250247            if (control is SplitContainer)
    251248            {
    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);
    254251
    255252                regKey.SetValue("SplitterDistance", (control as SplitContainer).SplitterDistance);
  • Common/FormFind.Designer.cs

    r3 r14  
    1 namespace Common
     1namespace Common
    22{
    33    partial class FormFind
     
    4141            //
    4242            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(405, 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);
    4545            this.buttonFindNext.Name = "buttonFindNext";
    46             this.buttonFindNext.Size = new System.Drawing.Size(117, 28);
     46            this.buttonFindNext.Size = new System.Drawing.Size(132, 35);
    4747            this.buttonFindNext.TabIndex = 4;
    4848            this.buttonFindNext.Text = "Find next";
     
    5454            this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    5555            this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    56             this.buttonCancel.Location = new System.Drawing.Point(405, 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);
    5858            this.buttonCancel.Name = "buttonCancel";
    59             this.buttonCancel.Size = new System.Drawing.Size(116, 28);
     59            this.buttonCancel.Size = new System.Drawing.Size(130, 35);
    6060            this.buttonCancel.TabIndex = 6;
    6161            this.buttonCancel.Text = "Cancel";
     
    6666            //
    6767            this.label1.AutoSize = true;
    68             this.label1.Location = new System.Drawing.Point(16, 21);
     68            this.label1.Location = new System.Drawing.Point(18, 26);
    6969            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
    7070            this.label1.Name = "label1";
    71             this.label1.Size = new System.Drawing.Size(72, 17);
     71            this.label1.Size = new System.Drawing.Size(82, 20);
    7272            this.label1.TabIndex = 0;
    7373            this.label1.Text = "Find what:";
     74            this.label1.Click += new System.EventHandler(this.label1_Click);
    7475            //
    7576            // checkBoxMatchWholeWordOnly
    7677            //
    7778            this.checkBoxMatchWholeWordOnly.AutoSize = true;
    78             this.checkBoxMatchWholeWordOnly.Location = new System.Drawing.Point(20, 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);
    8081            this.checkBoxMatchWholeWordOnly.Name = "checkBoxMatchWholeWordOnly";
    81             this.checkBoxMatchWholeWordOnly.Size = new System.Drawing.Size(172, 21);
     82            this.checkBoxMatchWholeWordOnly.Size = new System.Drawing.Size(193, 24);
    8283            this.checkBoxMatchWholeWordOnly.TabIndex = 2;
    8384            this.checkBoxMatchWholeWordOnly.Text = "Match whole word only";
    8485            this.checkBoxMatchWholeWordOnly.UseVisualStyleBackColor = true;
     86            this.checkBoxMatchWholeWordOnly.CheckedChanged += new System.EventHandler(this.checkBoxMatchWholeWordOnly_CheckedChanged);
    8587            //
    8688            // checkBoxMatchCase
    8789            //
    8890            this.checkBoxMatchCase.AutoSize = true;
    89             this.checkBoxMatchCase.Location = new System.Drawing.Point(20, 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);
    9193            this.checkBoxMatchCase.Name = "checkBoxMatchCase";
    92             this.checkBoxMatchCase.Size = new System.Drawing.Size(102, 21);
     94            this.checkBoxMatchCase.Size = new System.Drawing.Size(116, 24);
    9395            this.checkBoxMatchCase.TabIndex = 3;
    9496            this.checkBoxMatchCase.Text = "Match case";
    9597            this.checkBoxMatchCase.UseVisualStyleBackColor = true;
     98            this.checkBoxMatchCase.CheckedChanged += new System.EventHandler(this.checkBoxMatchCase_CheckedChanged);
    9699            //
    97100            // buttonFindPrevious
    98101            //
    99102            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(405, 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);
    102105            this.buttonFindPrevious.Name = "buttonFindPrevious";
    103             this.buttonFindPrevious.Size = new System.Drawing.Size(116, 28);
     106            this.buttonFindPrevious.Size = new System.Drawing.Size(130, 35);
    104107            this.buttonFindPrevious.TabIndex = 5;
    105108            this.buttonFindPrevious.Text = "Find previous";
     
    112115            | System.Windows.Forms.AnchorStyles.Right)));
    113116            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);
    115119            this.comboBoxWhat.Name = "comboBoxWhat";
    116             this.comboBoxWhat.Size = new System.Drawing.Size(297, 24);
     120            this.comboBoxWhat.Size = new System.Drawing.Size(346, 28);
    117121            this.comboBoxWhat.TabIndex = 7;
     122            this.comboBoxWhat.SelectedIndexChanged += new System.EventHandler(this.comboBoxWhat_SelectedIndexChanged);
    118123            this.comboBoxWhat.TextChanged += new System.EventHandler(this.textBoxWhat_TextChanged);
    119124            this.comboBoxWhat.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxWhat_KeyPress);
     
    121126            // FormFind
    122127            //
    123             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
     128            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
    124129            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);
    126131            this.Controls.Add(this.comboBoxWhat);
    127132            this.Controls.Add(this.buttonFindPrevious);
     
    131136            this.Controls.Add(this.buttonCancel);
    132137            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);
    134139            this.MaximizeBox = false;
    135140            this.MinimizeBox = false;
    136             this.MinimumSize = new System.Drawing.Size(394, 162);
     141            this.MinimumSize = new System.Drawing.Size(440, 189);
    137142            this.Name = "FormFind";
    138143            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  • Common/FormFind.cs

    r13 r14  
    11using System;
    2 using System.Collections.Generic;
    3 using System.ComponentModel;
    4 using System.Data;
    52using System.Drawing;
    6 using System.Linq;
    7 using System.Text;
    8 using System.Threading.Tasks;
    93using System.Windows.Forms;
    104using Microsoft.Win32;
     
    9690            Theme.UseTheme(this);
    9791            DpiScaling.Apply(this);
    98             this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     92            Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
    9993            new FormDimensions().Load(this, Owner);
    10094            comboBoxWhat.Focus();
     
    112106        {
    113107            SaveToRegistry();
    114             richTextBox.formFind = null;
     108            richTextBox.FormFind = null;
    115109            new FormDimensions().Save(this, Owner);
    116110        }
     
    156150            comboBoxWhat.SaveToRegistry();
    157151        }
     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        }
    158172    }
    159173}
  • Common/FormProgress.Designer.cs

    r1 r14  
    4040            this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    4141            | 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);
    4344            this.progressBar1.Name = "progressBar1";
    44             this.progressBar1.Size = new System.Drawing.Size(320, 19);
     45            this.progressBar1.Size = new System.Drawing.Size(492, 29);
    4546            this.progressBar1.TabIndex = 0;
    4647            //
     
    5354            //
    5455            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);
    5658            this.labelOperation.Name = "labelOperation";
    57             this.labelOperation.Size = new System.Drawing.Size(16, 13);
     59            this.labelOperation.Size = new System.Drawing.Size(21, 20);
    5860            this.labelOperation.TabIndex = 1;
    5961            this.labelOperation.Text = "   ";
     
    6264            //
    6365            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);
    6568            this.labelTime.Name = "labelTime";
    66             this.labelTime.Size = new System.Drawing.Size(16, 13);
     69            this.labelTime.Size = new System.Drawing.Size(21, 20);
    6770            this.labelTime.TabIndex = 2;
    6871            this.labelTime.Text = "   ";
     
    7073            // FormProgress
    7174            //
    72             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     75            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
    7376            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);
    7578            this.Controls.Add(this.labelTime);
    7679            this.Controls.Add(this.labelOperation);
    7780            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);
    7983            this.Name = "FormProgress";
    8084            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  • Common/FormProgress.cs

    r2 r14  
    22using System.Collections.Generic;
    33using System.ComponentModel;
    4 using System.Data;
    54using System.Drawing;
    65using System.Linq;
    7 using System.Text;
    86using System.Windows.Forms;
    97
     
    1210    public partial class FormProgress : Form
    1311    {
    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;
    1715
    1816        public FormProgress()
     
    2018            InitializeComponent();
    2119
    22             tasks = new List<Progress>();
    23             currentTask = null;
     20            Tasks = new List<Progress>();
     21            CurrentTask = null;
    2422        }
    2523
     
    2725        {
    2826            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);
    3230            if (index >= 0)
    3331            {
    3432                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);
    3634            }
    3735            else current = 0;
     
    4038                else progressBar1.Value = total;
    4139            progressBar1.Visible = current > 0;
    42             if (currentTask != null) labelOperation.Text = currentTask.operation;
     40            if (CurrentTask != null) labelOperation.Text = CurrentTask.Operation;
    4341                else labelOperation.Text = "";
    4442            if ((current > 0) && (total > 0))
    4543            {
    46                 TimeSpan timeDiff = TimeSpan.FromSeconds((DateTime.Now - startTime).TotalSeconds / current * (total - current));
     44                TimeSpan timeDiff = TimeSpan.FromSeconds((DateTime.Now - StartTime).TotalSeconds / current * (total - current));
    4745                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;
    5048            }
    5149            else labelTime.Text = "";
     
    5654            Theme.UseTheme(this);
    5755            DpiScaling.Apply(this);
    58             this.Icon = Icon.ExtractAssociatedIcon(Application.Execut‌​ablePath);
     56            Icon = Icon.ExtractAssociatedIcon(Application.Execut‌​ablePath);
    5957
    6058            timer1_Tick(this, null);
     
    6563        private void FormProgress_FormClosing(object sender, FormClosingEventArgs e)
    6664        {
    67             currentTask.terminated = true;
     65            CurrentTask.Terminated = true;
    6866            timer1.Enabled = false;
    6967        }
     
    7169        private void bg_DoWork(object sender, DoWorkEventArgs e)
    7270        {
    73             currentTask.Execute();
    74             currentTask.completed = !currentTask.terminated;
     71            CurrentTask.Execute();
     72            CurrentTask.Completed = !CurrentTask.Terminated;
    7573        }
    7674
     
    7977            if (e.Error != null)
    8078            {
    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);
    8381            }
    84             if (!currentTask.terminated)
     82            if (!CurrentTask.Terminated)
    8583            {
    86                 int nextIndex = tasks.IndexOf(currentTask) + 1;
    87                 if (nextIndex < tasks.Count)
     84                int nextIndex = Tasks.IndexOf(CurrentTask) + 1;
     85                if (nextIndex < Tasks.Count)
    8886                {
    89                     currentTask = tasks[nextIndex];
     87                    CurrentTask = Tasks[nextIndex];
    9088                    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;
    9391                    bg.RunWorkerAsync();
    9492                }
     
    10098        public void AddTask(string name, Progress.CallbackEventHandler progressCallback)
    10199        {
    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);
    109109        }
    110110
    111111        public void StartTask(string name, Progress.CallbackEventHandler progressCallback)
    112112        {
    113             tasks.Clear();
     113            Tasks.Clear();
    114114            AddTask(name, progressCallback);
    115115            Start();
     
    118118        public void Start()
    119119        {
    120             if (tasks.Count > 0)
     120            if (Tasks.Count > 0)
    121121            {
    122                 startTime = DateTime.Now;
    123                 currentTask = tasks.First();
     122                StartTime = DateTime.Now;
     123                CurrentTask = Tasks.First();
    124124                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;
    127127                bg.RunWorkerAsync();
    128128                ShowDialog();
     
    133133        {
    134134            int completed = 0;
    135             foreach (var task in tasks)
     135            foreach (var task in Tasks)
    136136            {
    137                 if (task.completed) completed += 1;
     137                if (task.Completed) completed += 1;
    138138            }
    139             return completed == tasks.Count;
     139            return completed == Tasks.Count;
    140140        }
    141141    }
     
    143143    public interface IProgress
    144144    {
    145         void SetTotal(int Value);
    146         void SetProgress(int Value);
     145        void SetTotal(int value);
     146        void SetProgress(int value);
    147147        bool GetTerminated();
    148148        void SetOperation(string text);
     
    152152    public class Progress : IProgress
    153153    {
    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;
    159159        public delegate void CallbackEventHandler(Progress progress);
    160         public event CallbackEventHandler callback;
    161         public Exception exception;
     160        public event CallbackEventHandler Callback;
    162161
    163         public void SetTotal(int Value)
     162        public void SetTotal(int value)
    164163        {
    165             total = Value;
     164            Total = value;
    166165        }
    167166
    168         public void SetProgress(int Value)
     167        public void SetProgress(int value)
    169168        {
    170             current = Value;
     169            Current = value;
    171170        }
    172171
    173172        public bool GetTerminated()
    174173        {
    175             return terminated;
     174            return Terminated;
    176175        }
    177176
    178177        public void SetOperation(string text)
    179178        {
    180             operation = text;
     179            Operation = text;
    181180        }
    182181
    183182        public void Execute()
    184183        {
    185             if (callback != null) callback(this);
     184            Callback?.Invoke(this);
    186185        }
    187186    }
  • Common/ListViewComparer.cs

    r1 r14  
    22using System.Windows.Forms;
    33using System.Runtime.InteropServices;
    4 using System.Globalization;
     4using System.Collections;
    55
    66namespace Common
    77{
    8     public enum ColumnDataType  { String, Integer, DateTime };
     8    public enum ColumnDataType { String, Integer, DateTime, Decimal, Custom };
    99
    1010    // Supports sorting by column in ascending or descending order
    11     public class ListViewItemComparer : System.Collections.IComparer
     11    public class ListViewItemComparer : IComparer
    1212    {
    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)
    1717        {
    1818            // Determine if clicked column is already the column that is being sorted.
    19             if (column == this.column)
     19            if (newColumn == column)
    2020            {
    2121                // Reverse the current sort direction for this column.
     
    3232            {
    3333                // Set the column number that is to be sorted; default to ascending.
    34                 this.column = column;
     34                column = newColumn;
    3535                order = SortOrder.Ascending;
    3636            }
    3737        }
    3838
    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;
    4747        }
    4848
     
    5353        }
    5454
     55        public delegate int CompareItemEventHandler(ListViewItem x, ListViewItem y, int column);
     56
     57        public event CompareItemEventHandler OnCompareItem;
     58
    5559        public int Compare(object x, object y)
    5660        {
     61            ListViewItem listViewItemX = (ListViewItem)x;
     62            ListViewItem listViewItemY = (ListViewItem)y;
     63
    5764            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;
    99130            }
    100131        }
     
    103134        {
    104135            if (listView.ListViewItemSorter == null)
     136            {
    105137                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);
    108142            if ((column != -1) && (order != SortOrder.None))
    109143            {
     
    113147            listView.ColumnClick += delegate (object sender, ColumnClickEventArgs e)
    114148            {
    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);
    118152            };
    119153        }
     
    181215
    182216
    183         //This method used to set arrow icon
     217        // This method used to set arrow icon
    184218        public static void SetSortIcon(this ListView listView, int columnIndex, SortOrder order)
    185219        {
     
    189223            {
    190224                IntPtr columnPtr = new IntPtr(columnNumber);
    191                 LVCOLUMN lvColumn = new LVCOLUMN();
    192                 lvColumn.mask = HDI_FORMAT;
     225                LVCOLUMN lvColumn = new LVCOLUMN {mask = HDI_FORMAT};
    193226
    194227                SendMessageLVCOLUMN(columnHeader, HDM_GETITEM, columnPtr, ref lvColumn);
    195228
    196                 if (!(order == SortOrder.None) && columnNumber == columnIndex)
     229                if (order != SortOrder.None && columnNumber == columnIndex)
    197230                {
    198231                    switch (order)
    199232                    {
    200                         case System.Windows.Forms.SortOrder.Ascending:
     233                        case SortOrder.Ascending:
    201234                            lvColumn.fmt &= ~HDF_SORTDOWN;
    202235                            lvColumn.fmt |= HDF_SORTUP;
    203236                            break;
    204                         case System.Windows.Forms.SortOrder.Descending:
     237                        case SortOrder.Descending:
    205238                            lvColumn.fmt &= ~HDF_SORTUP;
    206239                            lvColumn.fmt |= HDF_SORTDOWN;
  • Common/Prompt.cs

    r13 r14  
    11using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    52using System.IO;
    6 using System.Threading.Tasks;
    73using System.Drawing;
    84using System.Windows.Forms;
     
    2521            TextBox textBox = new TextBox() { Left = 50, Top = 44, Width = 400, Text = initialValue };
    2622            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 };
    2824            confirmation.Click += (sender, e) => { prompt.Close(); };
    2925            prompt.Controls.Add(textBox);
     
    3127            prompt.Controls.Add(textLabel);
    3228            prompt.AcceptButton = confirmation;
    33             prompt.Load += delegate (object sender3, EventArgs e3)
     29            prompt.Load += delegate
    3430            {
    3531                Theme.UseTheme(prompt);
     
    7167            };
    7268            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 };
    7470            confirmation.Click += (sender, e) => { prompt.Close(); };
    7571            prompt.Controls.Add(numericUpDown);
     
    7773            prompt.Controls.Add(textLabel);
    7874            prompt.AcceptButton = confirmation;
    79             prompt.Load += delegate (object sender3, EventArgs e3)
     75            prompt.Load += delegate
    8076            {
    8177                Theme.UseTheme(prompt);
     
    117113                comboBox.SelectedIndex = 0;
    118114            }
    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 };
    120116            confirmation.Click += (sender, e) => { prompt.Close(); };
    121117            prompt.Controls.Add(comboBox);
     
    123119            prompt.Controls.Add(textLabel);
    124120            prompt.AcceptButton = confirmation;
    125             prompt.Load += delegate (object sender3, EventArgs e3)
     121            prompt.Load += delegate
    126122            {
    127123                Theme.UseTheme(prompt);
     
    155151            Button confirmation = new Button()
    156152            {
    157                 Text = "Ok",
     153                Text = @"Ok",
    158154                Left = 350,
    159155                Width = 100,
     
    193189            prompt.Controls.Add(textLabel);
    194190            prompt.AcceptButton = confirmation;
    195             prompt.Load += delegate (object sender3, EventArgs e3)
     191            prompt.Load += delegate
    196192            {
    197193                Theme.UseTheme(prompt);
     
    224220            Label textLabel = new Label() { Left = 50, Top = 20, AutoSize = true, Text = text };
    225221            RichTextBox textBox = new RichTextBox() { Left = 50, Top = 44, Width = 400, Height = dataSize, Text = initialValue };
     222            textBox.TextChanged += delegate
     223            {
     224                Theme.UseTheme(prompt);
     225            };
    226226            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 };
    228228            confirmation.Click += (sender, e) => { prompt.Close(); };
    229229            prompt.Controls.Add(textBox);
     
    231231            prompt.Controls.Add(textLabel);
    232232            prompt.AcceptButton = confirmation;
    233             prompt.Load += delegate (object sender3, EventArgs e3)
     233            prompt.Load += delegate
    234234            {
    235235                Theme.UseTheme(prompt);
     
    260260        {
    261261            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 };
    264264            if (!string.IsNullOrEmpty(fileName))
    265265            {
     
    282282        {
    283283            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|*.*",
    288288                DefaultExt = fileExtension
    289289            };
  • Common/RecentFiles.cs

    r13 r14  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
    5 using System.Threading.Tasks;
    63using System.Windows.Forms;
    74using Microsoft.Win32;
     
    4239        }   
    4340
    44         public void LoadFromRegistry(string RegSubKey)
     41        public void LoadFromRegistry(string regSubKey)
    4542        {
    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);
    4845
    4946            int count = (int)regKey.GetValue("Count", 0);
     
    5653        }
    5754
    58         public void SaveToRegistry(string RegSubKey)
     55        public void SaveToRegistry(string regSubKey)
    5956        {
    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);
    6259
    6360            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;
    61using Microsoft.Win32;
    72
     
    1712                if ((string)value == "True") return true;
    1813                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;
    1926            }
    2027            else return defaultValue;
     
    3542        }
    3643
     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
    3752        public static long GetValueLong(this RegistryKey regKey, string name, long defaultValue)
    3853        {
    3954            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;
    4156            else return defaultValue;
    4257        }
     
    5469        public static void SetValueBool(this RegistryKey regKey, string name, bool value)
    5570        {
    56             regKey.SetValue(name, value);
     71            if (value) regKey.SetValue(name, "True");
     72                else regKey.SetValue(name, "False");
    5773        }
    5874
     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   
    5984        public static void SetValueString(this RegistryKey regKey, string name, string value)
    6085        {
     
    6691        {
    6792            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, "");
    68101        }
    69102
  • Common/RichTextBoxEx.Designer.cs

    r1 r14  
    1 namespace Common
     1namespace Common
    22{
    33    partial class RichTextBoxEx
  • Common/RichTextBoxEx.cs

    r13 r14  
    99    public partial class RichTextBoxEx : RichTextBox
    1010    {
    11         private bool linksActive = false;
     11        private bool linksActive;
    1212        public delegate void LinkClickHandler(string link);
    1313        public event LinkClickHandler LinkClick;
    1414        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;
    1919        private ToolStripMenuItem tsmiUndo;
    2020        private ToolStripMenuItem tsmiRedo;
     
    3131        {
    3232            //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
    3939            {
    4040                if (interfaceUpdateEnabled) UpdateInterface();
    4141            };
    4242            AddContextMenu();
    43             linkMatches = new List<LinkMatch>();
     43            LinkMatches = new List<LinkMatch>();
    4444        }
    4545
     
    5454            ReadOnly = false;
    5555            interfaceUpdateEnabled = false;
    56             previousRtf = Rtf;
     56            PreviousRtf = Rtf;
    5757            RichTextBoxContext context = new RichTextBoxContext();
    5858            context.SaveContext(this);
    5959            List<int> linkMatchStart = new List<int>();
    60             foreach (var linkMatch in linkMatches)
     60            foreach (var linkMatch in LinkMatches)
     61            {
    6162                linkMatchStart.Add(-2);
     63            }
     64
    6265            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());
    6568
    6669            string content = richTextBox.Text;
     
    7174
    7275            int contentStart = 0;
    73             int selectionStart = 0;
    7476            do
    7577            {
     
    7981                {
    8082                    int i = 0;
    81                     foreach (var linkMatch in linkMatches)
     83                    foreach (var linkMatch in LinkMatches)
    8284                    {
    8385                        if ((linkMatchStart[i] < contentStart) && (linkMatchStart[i] != -1))
    8486                        {
    85                             if (linkMatch.caseSensitive)
     87                            if (linkMatch.CaseSensitive)
    8688                            {
    87                                 linkMatchStart[i] = content.IndexOf(linkMatch.startString, contentStart, StringComparison.Ordinal);
     89                                linkMatchStart[i] = content.IndexOf(linkMatch.StartString, contentStart, StringComparison.Ordinal);
    8890                            } else
    8991                            {
     
    103105
    104106                int index = firstIndex;
    105                 string startString = firstMatch.startString;
     107                string startString = firstMatch.StartString;
    106108
    107109                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) &&
    114115                        ((index < 1) ||
    115116                        ((index >= 1) && ((content[index - 1] == ' ') || (content[index - 1] == '\n'))))
     
    175176        public void UndoUnknownActions()
    176177        {
     178            int i = 0;
    177179            while (CanUndo && (UndoActionId == UndoNameId.Unknown))
    178180            {
    179181                Undo();
    180             }
    181         }
    182 
    183         private void HideRichTextBoxLinks(RichTextBox richTextBox)
     182                i++;
     183                if (i > 1000) break;
     184            }
     185        }
     186
     187        private void HideRichTextBoxLinks()
    184188        {
    185189            bool lastReadOnlyState = ReadOnly;
     
    188192            RichTextBoxContext context = new RichTextBoxContext();
    189193            context.SaveContext(this);
    190             Rtf = previousRtf;
     194            Rtf = PreviousRtf;
    191195            UndoUnknownActions();
    192196
     
    219223            if ((e.KeyCode == Keys.ControlKey) && linksActive)
    220224            {
    221                 HideRichTextBoxLinks(this);
     225                HideRichTextBoxLinks();
    222226                linksActive = false;
    223227            }
     
    228232            if ((e.Button == MouseButtons.Left) && linksActive)
    229233            {
    230                 int linkStart = 0;
    231                 int linkEnd = 0;
     234                int linkStart;
     235                int linkEnd;
    232236                int mousePointerCharIndex = GetCharIndexFromPosition(e.Location);
    233237                SelectionStart = mousePointerCharIndex;
     
    238242                    {
    239243                        SelectionStart -= 1;
    240                         continue;
    241244                    }
    242245                    else
     
    257260                    {
    258261                        SelectionStart += 1;
    259                         continue;
    260262                    }
    261263                    else
     
    273275                    if (link != "")
    274276                    {
    275                         foreach (var linkMatch in linkMatches)
     277                        foreach (var linkMatch in LinkMatches)
    276278                        {
    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()))))
    280282                            {
    281                                 string linkNumber = link.Substring(linkMatch.startString.Length).Trim(new char[] { ' ', '#' });
     283                                string linkNumber = link.Substring(linkMatch.StartString.Length).Trim(new char[] { ' ', '#' });
    282284                                if (int.TryParse(linkNumber, out int number))
    283285                                {
     
    287289                            }
    288290                        }
    289                         if (LinkClick != null) LinkClick(link);
    290                         HideRichTextBoxLinks(this);
     291
     292                        LinkClick?.Invoke(link);
     293                        HideRichTextBoxLinks();
    291294                        linksActive = false;
    292295                    }
     
    297300        public void ShowInWindow()
    298301        {
    299             Form textForm = new Form()
     302            Form textForm = new Form
    300303            {
    301304                Name = "FormRichTextBox",
     
    304307                FormBorderStyle = FormBorderStyle.Sizable,
    305308                Text = Title,
    306                 Font = new Font(this.Font.FontFamily, this.Font.Size),
     309                Font = new Font(Font.FontFamily, Font.Size),
    307310                StartPosition = FormStartPosition.CenterScreen,
     311                Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath),
    308312            };
    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); }
    320322            };
    321323            textForm.Controls.Add(richTextBox);
    322             textForm.Load += delegate (object sender3, EventArgs e3)
     324            textForm.Load += delegate
    323325            {
    324326                Theme.UseTheme(textForm);
    325327                DpiScaling.Apply(textForm);
    326                 new FormDimensions().Load(textForm, parentForm);
     328                new FormDimensions().Load(textForm, ParentForm);
    327329                richTextBox.ClearUndo();
    328330            };
    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);
    332334            };
    333335            textForm.Show();
     
    336338        private void UpdateInterface()
    337339        {
    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;
    341343            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;
    344346            tsmiSelectAll.Enabled = (TextLength > 0) && (SelectionLength < TextLength);
    345347        }
     
    349351            if (linksActive)
    350352            {
    351                 HideRichTextBoxLinks(this);
     353                HideRichTextBoxLinks();
    352354                linksActive = false;
    353355            }
     
    435437                tsmiFind.Click += (sender, e) => {
    436438                    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();
    445447                };
    446448                tsmiFind.ShortcutKeys = Keys.F | Keys.Control;
     
    514516    public class LinkMatch
    515517    {
    516         public string startString;
    517         public bool caseSensitive;
     518        public string StartString;
     519        public bool CaseSensitive;
    518520        public delegate bool MatchHandler(string inContent, int startIndex, out string outContent);
    519521        public delegate void LinkActionHandler(int number);
     
    523525        public LinkMatch(string startString, MatchHandler matchHandler, LinkActionHandler action)
    524526        {
    525             this.startString = startString;
     527            StartString = startString;
    526528            Match = matchHandler;
    527529            LinkAction = action;
     
    551553
    552554            // Try to connect to following number
    553             string number;
    554555            numberStart = startIndex;
    555556            while (((content.Length - numberStart) >= 1) && ((content[numberStart] == ' ') || (content[numberStart] == '#')))
     
    564565                i++;
    565566            }
    566             number = content.Substring(numberStart, i);
     567            var number = content.Substring(numberStart, i);
    567568
    568569            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"?>
    22<root>
    33  <!--
  • Common/Table.cs

    r13 r14  
    11using System;
    22using System.Collections.Generic;
    3 using System.Diagnostics.Eventing.Reader;
    43using System.Linq;
     4using System.Windows.Forms;
    55using System.Text;
    6 using System.Threading.Tasks;
    76
    87namespace Common
    98{
    10     public class Row
    11     {
    12         public List<string> cells = new List<string>();
    13 
    14         public void AddCell(string text)
    15         {
    16             cells.Add(text);
    17         }
    18     }
    19 
    209    public enum OutputFormat
    2110    {
    2211        Excel,
    2312        Plain,
    24         Csv
     13        Csv,
     14        Html,
     15        ListView
    2516    };
     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    }
    2627
    2728    public class Table
    2829    {
    29         public List<Row> rows = new List<Row>();
     30        public List<Row> Rows = new List<Row>();
    3031
    3132        public void Clear()
    3233        {
    33             rows.Clear();
     34            Rows.Clear();
    3435        }
    3536
     
    3738        {
    3839            Row row = new Row();
    39             rows.Add(row);
     40            Rows.Add(row);
    4041            return row;
    4142        }
     
    4445        {
    4546            StringBuilder output = new StringBuilder();
    46             foreach (var row in rows)
     47            foreach (var row in Rows)
    4748            {
    48                 output.AppendLine(string.Join("\t", row.cells));
     49                output.AppendLine(string.Join("\t", row.Cells));
    4950            }
    5051            return output.ToString();
     
    5455        {
    5556            StringBuilder output = new StringBuilder();
    56             foreach (var row in rows)
     57            foreach (var row in Rows)
    5758            {
    58                 output.AppendLine(string.Join(Environment.NewLine, row.cells));
     59                output.AppendLine(string.Join(Environment.NewLine, row.Cells));
    5960                output.AppendLine();
    6061                output.AppendLine("===========================");
     
    6768        {
    6869            StringBuilder output = new StringBuilder();
    69             foreach (var row in rows)
     70            foreach (var row in Rows)
    7071            {
    71                 output.AppendLine(string.Join(",", row.cells.Select(x => "\"" + x + "\"")));
     72                output.AppendLine(string.Join(",", row.Cells.Select(x => "\"" + x + "\"")));
    7273            }
    7374            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            }
    74118        }
    75119
     
    79123            else if (outputFormat == OutputFormat.Plain) return GetOutputPlain();
    80124            else if (outputFormat == OutputFormat.Csv) return GetOutputCsv();
     125            else if (outputFormat == OutputFormat.Html) return GetOutputHtml();
    81126            else return "";
    82127        }
  • 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;
    61using System.Windows.Forms;
    72using System.Drawing;
    83using System.ComponentModel;
    9 using System.IO;
    104
    115namespace Common
     
    148    {
    159        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 string name;
    24         static public string Name
    25         {
    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;
    2721            set
    2822            {
    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                }
    5649            }
    5750        }
     
    7265                    // Exchange dark with light colors and vice versa
    7366                    if (color == Color.DarkBlue) color = Color.LightBlue;
    74                     if (color == Color.LightBlue) color = Color.DarkBlue;
     67                    else if (color == Color.LightBlue) color = Color.DarkBlue;
    7568                    else if (color == Color.DarkGreen) color = Color.LightGreen;
    7669                    else if (color == Color.LightGreen) color = Color.DarkGreen;
     
    9790        public static void ApplyTheme(Component component)
    9891        {
    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)
    10295                {
    10396                    ApplyTheme(child);
    10497                }
    10598
    106                 if ((component is TextBox) || (component is NumericUpDown) || (component is ComboBox) || (component is RichTextBox)
    107                     || (component is 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;
    111104                }
    112105                else
    113106                {
    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)
    136133                {
    137134                    ApplyTheme(tabPage);
    138135                }
    139136            } 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)
    147144                    {
    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)
    151148                            {
    152149                                ApplyTheme(dropDownItem);
    153150                            }
     151                        }
    154152                    }
    155153                    ApplyTheme(item);
    156154                }
    157155            } 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            }
    179188        }
    180189
    181190        public static void UseTheme(Form form)
    182191        {
    183             if (!used && (name == "System")) return;
     192            if (!Used && (_name == "System")) return;
    184193            ApplyTheme(form);
    185             used = true;
     194            Used = true;
    186195        }
    187196    }
     
    189198    public class ThemeColorTable : ProfessionalColorTable
    190199    {
    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;
    326217    }
    327218}
Note: See TracChangeset for help on using the changeset viewer.