Example #1
0
        /// <summary>
        /// Open a <c>OpenFileDialog</c>.
        /// </summary>
        /// <returns>The filepath that was selected or null if none was selected.</returns>
        public static string OpenFileSelector()
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                // Initialize our values:
                ofd.InitialDirectory = FileDialogHandler.InitialDirectory;
                ofd.Filter           = FileDialogHandler.Filter;
                ofd.FilterIndex      = FileDialogHandler.FilterIndex;
                ofd.RestoreDirectory = FileDialogHandler.RestoreDirectory;

                DialogResult dialog = ofd.ShowDialog();

                // Check if our dialog went successful.
                switch (dialog)
                {
                case DialogResult.OK:
                    return(ofd.FileName);

                case DialogResult.Retry:
                    return(FileDialogHandler.OpenFileSelector());

                default:
                    return(null);
                }
            }
        }
Example #2
0
        private void ParseWatermark_Click(object sender, EventArgs e)
        {
            string fp = FileDialogHandler.OpenFileSelector();

            // If a file has been selected:
            if (fp != null)
            {
                new ParseWatermark(fp).Show();
            }
            else
            {
                this.HandleError(this.ParseWatermark_Click, sender, e);
            }
        }