Changeset 12


Ignore:
Timestamp:
Mar 14, 2020, 1:11:28 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved classes.
Location:
Common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Common/FormDimensions.cs

    r5 r12  
    1 using System;
     1using System;
    22using System.Collections.Generic;
    33using System.Linq;
     
    77using System.Runtime.InteropServices;
    88using Microsoft.Win32;
    9 
    109
    1110namespace Common
     
    212211                }
    213212            }
     213            if (control is SplitContainer)
     214            {
     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);
     217
     218                if (regKey.GetValue("SplitterDistance") != null)
     219                    (control as SplitContainer).SplitterDistance = (int)regKey.GetValue("SplitterDistance");
     220            }
    214221
    215222            foreach (Control child in control.Controls)
     
    240247                    regKey.SetValue("ColWidth" + I.ToString(), (control as DataGridView).Columns[I].Width);
    241248                }
     249            }
     250            if (control is SplitContainer)
     251            {
     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);
     254
     255                regKey.SetValue("SplitterDistance", (control as SplitContainer).SplitterDistance);
    242256            }
    243257
  • Common/Prompt.cs

    r8 r12  
    33using System.Linq;
    44using System.Text;
     5using System.IO;
    56using System.Threading.Tasks;
    67using System.Drawing;
     
    162163            };
    163164            confirmation.Click += (sender, e) => { prompt.Close(); };
    164             ListBox listBox = new ListBox() { Left = 50, Top = 44, Width = 400, Height = dataSize,
     165            ListBox listBox = new ListBox()
     166            {
     167                Left = 50,
     168                Top = 44,
     169                Width = 400,
     170                Height = dataSize,
    165171                Anchor = AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left
    166172            };
     
    248254        }
    249255    }
     256
     257    public static class PromptOpenFile
     258    {
     259        public static bool ShowDialog(string fileName, string fileType, string fileExtension, out string result)
     260        {
     261            result = fileName;
     262            OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = fileType + " (." + fileExtension + ")|*." +
     263                fileExtension + "|Any file|*.*", DefaultExt = fileExtension };
     264            if (!string.IsNullOrEmpty(fileName))
     265            {
     266                openFileDialog.FileName = Path.GetFileName(fileName);
     267                openFileDialog.InitialDirectory = Path.GetDirectoryName(fileName);
     268            }
     269
     270            DialogResult dialogResult = openFileDialog.ShowDialog();
     271            if (dialogResult == DialogResult.OK)
     272            {
     273                result = openFileDialog.FileName;
     274            }
     275            return dialogResult == DialogResult.OK;
     276        }
     277    }
     278
     279    public static class PromptSaveFile
     280    {
     281        public static bool ShowDialog(string fileName, string fileType, string fileExtension, out string result)
     282        {
     283            result = fileName;
     284            SaveFileDialog saveFileDialog = new SaveFileDialog()
     285            {
     286                Filter = fileType + " (." + fileExtension + ")|*." +
     287                fileExtension + "|Any file|*.*",
     288                DefaultExt = fileExtension
     289            };
     290            if (!string.IsNullOrEmpty(fileName))
     291            {
     292                saveFileDialog.FileName = Path.GetFileName(fileName);
     293                saveFileDialog.InitialDirectory = Path.GetDirectoryName(fileName);
     294            }
     295
     296            DialogResult dialogResult = saveFileDialog.ShowDialog();
     297            if (dialogResult == DialogResult.OK)
     298            {
     299                result = saveFileDialog.FileName;
     300            }
     301            return dialogResult == DialogResult.OK;
     302        }
     303    }
     304
     305    public static class PromptOpenDir
     306    {
     307        public static bool ShowDialog(string dirName, out string result)
     308        {
     309            result = dirName;
     310            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog() { ShowNewFolderButton = true };
     311            if (!string.IsNullOrEmpty(dirName))
     312                folderBrowserDialog.SelectedPath = dirName;
     313            DialogResult dialogResult = folderBrowserDialog.ShowDialog();
     314            if (dialogResult == DialogResult.OK)
     315            {
     316                result = folderBrowserDialog.SelectedPath;
     317            }
     318            return dialogResult == DialogResult.OK;
     319        }
     320    }
    250321}
  • Common/Theme.cs

    r4 r12  
    1 using System;
     1using System;
    22using System.Collections.Generic;
    33using System.Linq;
     
    77using System.Drawing;
    88using System.ComponentModel;
     9using System.IO;
    910
    1011namespace Common
     
    6162        }
    6263
     64        public static Color AdjustColor(Color color)
     65        {
     66            if (color == Color.White) color = ColorWindow;
     67            else if (color == Color.Black) color = ColorWindowText;
     68            else
     69            {
     70                if (Name == "Dark")
     71                {
     72                    // Exchange dark with light colors and vice versa
     73                    if (color == Color.DarkBlue) color = Color.LightBlue;
     74                    if (color == Color.LightBlue) color = Color.DarkBlue;
     75                    else if (color == Color.DarkGreen) color = Color.LightGreen;
     76                    else if (color == Color.LightGreen) color = Color.DarkGreen;
     77                    else if (color == Color.DarkRed) color = Color.LightCoral;
     78                    else if (color == Color.LightCoral) color = Color.DarkRed;
     79                    else if (color == Color.PowderBlue) color = Color.Navy;
     80                    else if (color == Color.Navy) color = Color.PowderBlue;
     81                    else if (color == Color.LightCyan) color = Color.DarkCyan;
     82                    else if (color == Color.DarkCyan) color = Color.LightCyan;
     83                    else if (color == Color.Cyan) color = Color.Teal;
     84                    else if (color == Color.Teal) color = Color.Cyan;
     85                    else if (color == Color.Yellow) color = Color.Brown;
     86                    else if (color == Color.Brown) color = Color.Yellow;
     87                    else if (color == Color.LightGray) color = Color.DarkGray;
     88                    else if (color == Color.DarkGray) color = Color.LightGray;
     89                }
     90            }
     91
     92            return color;
     93        }
     94
    6395        public static void ApplyTheme(Component component)
    6496        {
Note: See TracChangeset for help on using the changeset viewer.