// TODO:
 // Get the file name and path from dialog input
 public static string GetFilePath(System.Windows.Forms.FileDialog file)
 {
     file.ShowDialog();
     // release resource from FileDialog
     // dialog hangs when running and closing window multiple times without Dispose() method
     file.Dispose();
     return(file.InitialDirectory + file.FileName);
 }
예제 #2
0
 private void handleDialog(System.Windows.Forms.FileDialog dialog, Action <String> pathAction)
 {
     dialog.Filter           = "Sudoku (*.sudoku)|*.sudoku";
     dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
     if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         pathAction.Invoke(dialog.FileName);
     }
     dialog.Dispose();
 }
예제 #3
0
        // Methods

        public void GetFileName()
        {
            IntPtr        ptr     = GetForegroundWindow();
            WindowWrapper oWindow = new WindowWrapper(ptr);

            if (_oFileDialog.ShowDialog(oWindow) != System.Windows.Forms.DialogResult.OK)
            {
                _oFileDialog.FileName = string.Empty;
            }
            oWindow = null;
        }     // End of GetFileName
예제 #4
0
 static public bool DialogResultIsOK(System.Windows.Forms.FileDialog ofd, string filter)
 {
                 #if WPF4
     throw new NotImplementedException("hehaw (not implemented).");
                 #else
     if (filter != null)
     {
         ofd.Filter = filter;
     }
     return(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK);
                 #endif
 }
        private void openExistQuestionBank(object sender, EventArgs e)
        {
            //if (Properties.Settings.Default["LastFolderPath"].ToString() != "")
            //{
            //    openFileDialog1.InitialDirectory = Properties.Settings.Default["LastFolderPath"].ToString();
            //}

            //  if (Properties.Settings.Default["LastFolderPath"].ToString() != "")
            //{
            //    openFileDialog1.InitialDirectory = Properties.Settings.Default["LastFolderPath"].ToString();
            // }

            System.Windows.Forms.DialogResult dr = openFileDialog1.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                QBManager.FileName = openFileDialog1.FileName;

                // Saves settings in application configuration file
                //Properties.Settings.Default["LastFolderPath"] = System.IO.Path.GetDirectoryName(openFileDialog1.FileName);
                //Properties.Settings.Default.Save();

                //toolStripStatusLabel1.Text = openFileDialog1.FileName;

                QBManager.Load();
                if (QBManager.QBank.Mode == null)
                {
                    QBManager.QBank.Mode = "Operator";
                }

                //.Rows.Clear();
                List <Question> list = QBManager.QBank.Questions;
                foreach (Question q in list)
                {
                    itmsQuestions.Items.Add(q);
                }

                //toolStripStatusLabel3.Text = QBManager.QBank.ExamGrade;
                //toolStripStatusLabel4.Text = QBManager.QBank.LastModifiedDate.ToString();

                //editDetailsToolStripMenuItem.Enabled = true;
                //newQuestionToolStripMenuItem.Enabled = true;
                //toolStripMenuItem3.Enabled = true;
                //syncToolStripMenuItem.Enabled = true;
            }
        }
예제 #6
0
        private string PromptForFile(FileTypes type, bool existing)
        {
            using (System.Windows.Forms.FileDialog fileDialog = existing ? ((System.Windows.Forms.FileDialog) new System.Windows.Forms.OpenFileDialog()) : ((System.Windows.Forms.FileDialog) new System.Windows.Forms.SaveFileDialog()))
            {
                switch (type)
                {
                case FileTypes.Disc:
                    fileDialog.DefaultExt = "zip";
                    fileDialog.Filter     = "Disc files (*.dsk;*.zip)|*.dsk;*.zip|All files (*.*)|*.*";
                    break;

                case FileTypes.Tape:
                    fileDialog.DefaultExt = "zip";
                    fileDialog.Filter     = "Tape files (*.cdt;*.tzx;*.zip)|*.cdt;*.tzx;*.zip|All files (*.*)|*.*";
                    break;

                case FileTypes.Machine:
                    fileDialog.DefaultExt = "cpvc";
                    fileDialog.Filter     = "CPvC files (*.cpvc)|*.cpvc|All files (*.*)|*.*";
                    break;

                default:
                    throw new Exception(String.Format("Unknown FileTypes value {0}.", type));
                }

                fileDialog.AddExtension = true;

                string initialFolder = _settings.GetFolder(type);
                if (initialFolder != null)
                {
                    fileDialog.InitialDirectory = initialFolder;
                }

                System.Windows.Forms.DialogResult result = fileDialog.ShowDialog();
                if (result != System.Windows.Forms.DialogResult.OK)
                {
                    return(null);
                }

                // Remember the last folder for the selected filetype.
                string folder = System.IO.Path.GetDirectoryName(fileDialog.FileName);
                _settings.SetFolder(type, folder);

                return(fileDialog.FileName);
            }
        }