Changeset 12 for Common/Prompt.cs


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

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.