Пример #1
0
    public static string ShowFileDialog(string FileName, string fileFull, System.Windows.Forms.FileDialog dialog, Form parent)
    {
        string selectedPath = "";
        var    t            = new Thread((ThreadStart)(() =>
        {
            HandsFreeLeveler.Program.homePage.BeginInvoke(new Action(
                                                              delegate()
            {
                parent.Activate();
                parent.TopMost = true;  // important
                parent.TopMost = false; // important
                parent.Focus();
                parent.BringToFront();
            }));
            dialog.Filter = FileName + "|" + fileFull;
            dialog.FileName = FileName;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                selectedPath = dialog.FileName;
            }
        }));

        t.SetApartmentState(ApartmentState.STA);
        t.Start();
        t.Join();
        return(selectedPath);
    }
Пример #2
0
        private void AmbilFile(FileDialog dialog, TextBox control, bool useFilter)
        {
            if (useFilter) { dialog.Filter = "Wave Audio (*.wav)|*.wav"; }
            if (dialog.ShowDialog(this) == DialogResult.OK)

                control.Text = dialog.FileName;
        }
 public void imageOCRTest(FileDialog openImageDialog )
 {
     DialogResult ImageResult = openImageDialog.ShowDialog();
      if (ImageResult == DialogResult.OK)
      {
          String testImagePath = openImageDialog.FileName;
          try
          {
              using (var tEngine = new TesseractEngine("C:\\Users\\yeghiakoronian\\Documents\\visual studio 2013\\Projects\\NLP Genre Recogition\\NLP Genre Recogition\\tessdata", "eng", EngineMode.Default)) //creating the tesseract OCR engine with English as the language
              {
                  using (var img = Pix.LoadFromFile(testImagePath)) // Load of the image file from the Pix object which is a wrapper for Leptonica PIX structure
                  {
                      using (var page = tEngine.Process(img)) //process the specified image
                      {
                          String text = page.GetText(); //Gets the image's content as plain text.
                          MessageBox.Show(text);
                          getGenreOfSong(text);
                          //  Console.ReadKey();
                      }
                  }
              }
          }
          catch (IOException)
          {
              MessageBox.Show("Woops Cant Open The File", "COMP 6781: NLP", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
          }
      }
 }
		private static DialogResult StartDialog(FileDialog dialog, string extension, string description)
		{
			dialog.AddExtension = true;
			dialog.DefaultExt = extension;
			dialog.Filter = string.Format("{0}(*{1})|*{1}", description, extension);
			var result = dialog.ShowDialog();
			return result;
		}
Пример #5
0
 private void FileButtonClick(TextBox textBox, FileDialog dialog)
 {
     var result = dialog.ShowDialog();
     if (result == System.Windows.Forms.DialogResult.OK)
     {
         textBox.Text = dialog.FileName;
     }
     else
     {
         textBox.Text = "";
     }
 }
Пример #6
0
 private bool ShowFileDialog(WinForms.FileDialog dialog)
 {
     if (InitialDirectory != null)
     {
         dialog.InitialDirectory = InitialDirectory;
     }
     if (dialog.ShowDialog() == WinForms.DialogResult.OK)
     {
         FileName  = dialog.FileName;
         FileNames = dialog.FileNames;
         return(true);
     }
     return(false);
 }
Пример #7
0
        //When calling a OpenFileDialog it needs to be done from an STA thread model otherwise it throws:
        //"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process."
        private static DialogResult ShowDialogInSTA(FileDialog dialog)
        {
            var result = DialogResult.Cancel;

            var thread = new Thread(() =>
                {
                    result = dialog.ShowDialog();
                });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            return result;
        }
Пример #8
0
        public static string[] BrowseFile(System.Windows.Forms.FileDialog openFileDialog)
        {
            string[]     fileNames = new string[1];
            DialogResult dlgRes    = openFileDialog.ShowDialog();

            if (dlgRes == DialogResult.OK)
            {
                // store the selected filename on the currentFile
                fileNames = openFileDialog.FileNames;
            }
            else
            {
                fileNames = null;
            }
            return(fileNames);
        }
        private void DoProcess(string activity)
        {
            try
            {
                if (string.IsNullOrEmpty(Global.SqlLocalDbPath))
                {
                    _dialog = new OpenFileDialog();
                    _dialog.Title = "Locate SqlLocalDB.exe";
                    _dialog.FileName = "SqlLocalDB.exe";
                    _dialog.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
                    _dialog.InitialDirectory = Global.SqlLocalDbDefaultPath;
                    _dialog.FilterIndex = 1;
                    if (_dialog.ShowDialog() == DialogResult.OK)
                    {
                        Global.SqlLocalDbPath = "\"" + _dialog.FileName + "\"";
                    }
                }

                var info = new ProcessStartInfo(Global.SqlLocalDbPath, " " + activity + " " + txtInstanceName.Text);
                var p = new Process();
                p.StartInfo = info;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.Start();
                p.WaitForExit();
                var reader = p.StandardOutput;
                var output = reader.ReadToEnd();
                reader.Close();

                if (output.Length == 0)
                {
                    reader = p.StandardError;
                    var error = reader.ReadToEnd();
                    reader.Close();
                    txtResult.Text = error;
                } else {
                    txtResult.Text = output;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #10
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult returnDialogResult = DialogResult.Cancel;

            if (this.IsDisposed)
            {
                return(returnDialogResult);
            }
            if (owner == null || owner.Handle == IntPtr.Zero)
            {
                WindowWrapper wr = new WindowWrapper(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
                owner = wr;
            }
            OriginalCtrlSize = this.Size;

            _MSdialog = (FileDlgType == FileDialogType.OpenFileDlg) ? new OpenFileDialog() as FileDialog : new SaveFileDialog()
            {
                CreatePrompt = _CreatePrompt, CheckPathExists = _CheckPathExists
            } as FileDialog;
            _dlgWrapper = new WholeDialogWrapper(this);
            OnPrepareMSDialog();
            if (!_hasRunInitMSDialog)
            {
                InitMSDialog();
            }
            try
            {
                System.Reflection.PropertyInfo AutoUpgradeInfo = MSDialog.GetType().GetProperty("AutoUpgradeEnabled");
                if (AutoUpgradeInfo != null)
                {
                    AutoUpgradeInfo.SetValue(MSDialog, false, null);
                }
                returnDialogResult = _MSdialog.ShowDialog(owner);
            }
            // Sometimes if you open a animated .gif on the preview and the Form is closed, .Net class throw an exception
            // Lets ignore this exception and keep closing the form.
            catch (ObjectDisposedException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show("unable to get the modal dialog handle", ex.Message);
            }
            return(returnDialogResult);
        }
Пример #11
0
        protected IFileDialogAction ShowDialogNative(FileDialog dlg, Func<Stream> openFile)
        {
            this.AddStarPrefixToExtensions();
            dlg.Filter = this.GetFilter();
            dlg.InitialDirectory = IO.Path.GetDirectoryName(this.FilePath);
            dlg.FileName = IO.Path.GetFileNameWithoutExtension(this.FilePath);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                using (var stream = openFile())
                {
                    if (stream == null)
                        return null;
                    return this.RunAction(dlg.FilterIndex - 1, stream, dlg.FileName);
                }
            }
            return null;
        }
 // After first click at the Choose assembly button, in case when receipt of assembly file is done successfully, initializing MainWindow class' fields.
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         // Trying to get assembly from file and assign this to field, in case of success
         var file           = fileDialog.FileName;
         var pickedAssembly = AssemblyHelper.GetAssembly(file);
         if (pickedAssembly != null)
         {
             assemblyInfo             = new AssemblyInfo(pickedAssembly, MainGrid);
             backUps                  = new List <KeyValuePair <IEnumerable, TypeOfList> >();
             labelFileName.Content    = file.Substring(file.LastIndexOf("\\") + 1);
             labelFileName.Visibility = Visibility.Visible;
             listBoxMain.ItemsSource  = new object[0];
             backUps.Add(new KeyValuePair <IEnumerable, TypeOfList>(listBoxMain.ItemsSource, TypeOfList.Types));
         }
     }
 }
Пример #13
0
        public override WindowResponse Show()
        {
            if (DialogType == FileDialogType.SelectFolder)
            {
                fbdlg = new OpenFolderDialog();
                fbdlg.InitialFolder = InitialDirectory;
                fbdlg.Title         = Title;

                WindowResponse resp = WinFormHelper.GetResponse(fbdlg.ShowDialog(owner));
                SelectedPath = fbdlg.Folder;
                return(resp);
            }
            else
            {
                switch (DialogType)
                {
                case FileDialogType.OpenFile:
                    fdlg = new OpenFileDialog();
                    break;

                case FileDialogType.SaveFile:
                    fdlg = new SaveFileDialog();
                    break;
                }

                fdlg.InitialDirectory = InitialDirectory;
                fdlg.Title            = Title;
                string tmpFilter = string.Empty;

                foreach (FileTypeFilter filter in FileTypeFilters)
                {
                    tmpFilter += filter.FilterName + "|";
                    for (int i = 0; i < filter.Filter.Length; i++)
                    {
                        tmpFilter += (i == 0 ? "" : ";") + "*." + filter.Filter[i];
                    }
                }
                fdlg.Filter = tmpFilter;
                WindowResponse resp = WinFormHelper.GetResponse(fdlg.ShowDialog());
                SelectedPath = fdlg.FileName;
                return(resp);
            }
        }
Пример #14
0
        private Uri GetFileUrl(FileDialog dialog, Uri recentUri)
        {
            dialog.Filter = this.FileFilter;

            if (recentUri != null && recentUri.IsFile)
            {
                dialog.FileName = recentUri.LocalPath;
            }

            var result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                return new Uri(dialog.FileName);
            }
            else
            {
                return null;
            }
        }
Пример #15
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult returnDialogResult = DialogResult.Cancel;

            if (this.IsDisposed)
            {
                return(returnDialogResult);
            }
            if (owner == null || owner.Handle == IntPtr.Zero)
            {
                WindowWrapper wr = new WindowWrapper(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
                owner = wr;
            }
            if (FileDlgType == FileDialogType.OpenFileDlg)
            {
                _dlgWrapper = new DialogWrapper <OpenFileDialog>(this);
                ((OpenFileDialog)this.MSDialog).Multiselect = true;
            }
            else
            {
                _dlgWrapper = new DialogWrapper <SaveFileDialog>(this);
            }
            OnPrepareMSDialog();
            if (!_hasRunInitMSDialog)
            {
                InitMSDialog();
            }
            try
            {
                returnDialogResult = _MSdialog.ShowDialog(owner);
            }
            catch (ObjectDisposedException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show("unable to get the modal dialog handle", ex.Message);
            }
            return(returnDialogResult);
        }
Пример #16
0
        public override WindowResponse Show()
        {
            if (DialogType == FileDialogType.SelectFolder)
            {
                fbdlg = new OpenFolderDialog();
                fbdlg.InitialFolder = InitialDirectory;
                fbdlg.Title = Title;

                WindowResponse resp = WinFormHelper.GetResponse(fbdlg.ShowDialog(owner));
                SelectedPath = fbdlg.Folder;
                return resp;
            }
            else
            {
                switch (DialogType)
                {
                    case FileDialogType.OpenFile:
                        fdlg = new OpenFileDialog();
                        break;
                    case FileDialogType.SaveFile:
                        fdlg = new SaveFileDialog();
                        break;
                }

                fdlg.InitialDirectory = InitialDirectory;
                fdlg.Title = Title;
                string tmpFilter = string.Empty;

                foreach (FileTypeFilter filter in FileTypeFilters)
                {
                    tmpFilter += filter.FilterName + "|";
                    for (int i = 0; i < filter.Filter.Length; i++) tmpFilter += (i == 0 ? "" : ";") + "*." + filter.Filter[i];
                }
                fdlg.Filter = tmpFilter;
                WindowResponse resp = WinFormHelper.GetResponse(fdlg.ShowDialog());
                SelectedPath = fdlg.FileName;
                return resp;
            }
        }
Пример #17
0
        public DialogResult ShowDialog(IWin32Window owner)
        {
            DialogResult returnDialogResult = DialogResult.Cancel;

            if (this.IsDisposed)
            {
                return(returnDialogResult);
            }
            if (FileDlgType == FileDialogType.OpenFileDlg)
            {
                _dlgWrapper = new DialogWrapper <OpenFileDialog>(this);
            }
            else
            {
                _dlgWrapper = new DialogWrapper <SaveFileDialog>(this);
            }
            OnPrepareMSDialog();
            if (!_hasRunInitMSDialog)
            {
                InitMSDialog();
            }
            try
            {
                returnDialogResult = _MSdialog.ShowDialog(owner);
            }
            // Sometimes if you open a animated .gif on the preview and the Form is closed, .Net class throw an exception
            // Lets ignore this exception and keep closing the form.
            catch (ObjectDisposedException)
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show("unable to get the modal dialog handle", ex.Message);
            }
            return(returnDialogResult);
        }
Пример #18
0
        public bool FileDialog(FileDialog dialog, ref string path)
        {
            try
            {
                System.IO.FileInfo info = new System.IO.FileInfo(path);
                dialog.InitialDirectory = info.DirectoryName;
                dialog.FileName = info.Name;
            }
            catch { };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                path = dialog.FileName;

                return true;
            }

            return false;
        }
Пример #19
0
    public virtual void  actionPerformed(System.Object event_sender, System.EventArgs event_Renamed)
    {
        if (event_sender.Equals(openMenu))
        {
            chooser.ShowDialog(this);
            if (new System.IO.FileInfo(chooser.FileName) == null)
            {
                return;
            }
            try
            {
                sourceImage = ImageIO.read(new System.IO.FileInfo(chooser.FileName));
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
        else if (SupportClass.CommandManager.GetCommand(event_sender).Equals("Open from URL"))
        {
            try
            {
                //UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'"
                sourceImage = ImageIO.read(new System.Uri(url.Text));
            }
            catch (System.Exception e)
            {
                SupportClass.WriteStackTrace(e, Console.Error);
            }
        }
        else
        {
            return;
        }

        if (sourceImageLabel != null)
        {
            //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
            ((System.Windows.Forms.ContainerControl) this).Controls.Remove(sourceImageLabel);
        }

        System.Windows.Forms.Label temp_label;
        temp_label       = new System.Windows.Forms.Label();
        temp_label.Image = (System.Drawing.Image)sourceImage.Clone();
        sourceImageLabel = temp_label;
        //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
        //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'"
        ((System.Windows.Forms.ContainerControl) this).Controls.Add(sourceImageLabel);
        sourceImageLabel.Dock = System.Windows.Forms.DockStyle.Left;
        sourceImageLabel.BringToFront();


        QRCodeDecoder decoder = new QRCodeDecoder();

        if (canvas != null)
        {
            //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
            ((System.Windows.Forms.ContainerControl) this).Controls.Remove(canvas);
            //canvas.setImage(null);
        }
        canvas = new J2SEDebugCanvas();
        QRCodeDecoder.setCanvas(canvas);
        //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
        //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'"
        ((System.Windows.Forms.ContainerControl) this).Controls.Add(canvas);
        canvas.Dock = System.Windows.Forms.DockStyle.Right;
        canvas.BringToFront();
        System.String decodedString = null;
        try
        {
            decodedString = new String(decoder.decode(new J2SEImage(this, sourceImage)));
        }
        catch (DecodingFailedException e)
        {
            canvas.println(e.getMessage());
            canvas.println("--------");
            return;
        }
        decodedString = ContentConverter.convert(decodedString);
        canvas.println("\nDecode result:");
        canvas.println(decodedString);
        canvas.println("--------");
        if (decodedText != null)
        {
            //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
            ((System.Windows.Forms.ContainerControl) this).Controls.Remove(decodedText);
        }
        System.Windows.Forms.TextBox temp_TextBox;
        temp_TextBox            = new System.Windows.Forms.TextBox();
        temp_TextBox.Multiline  = true;
        temp_TextBox.WordWrap   = false;
        temp_TextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
        temp_TextBox.Text       = decodedString;
        decodedText             = temp_TextBox;
        decodedText.WordWrap    = true;
        //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setRows' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetRows_int'"
        decodedText.setRows(decodedString.Length / 20 + 1);
        if (decodedString.Length < 20)
        {
            //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setColumns' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetColumns_int'"
            decodedText.setColumns(decodedString.Length);
        }
        else
        {
            //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setColumns' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetColumns_int'"
            decodedText.setColumns(20);
        }
        //decodedText.setSize(sourceImageLabel.getSize().width,100);
        //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'"
        //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'"
        ((System.Windows.Forms.ContainerControl) this).Controls.Add(decodedText);
        decodedText.Dock = System.Windows.Forms.DockStyle.Bottom;
        decodedText.SendToBack();
        //UPGRADE_ISSUE: Method 'java.awt.Window.pack' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtWindowpack'"
        pack();
    }
Пример #20
0
        // Dialog Methods
        private string selectFile(FileDialog dialog, string filter)
        {
            dialog.Filter = filter;
            dialog.FilterIndex = 1;
            dialog.RestoreDirectory = true;

            // string path : Open Dialog box
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {
                return dialog.FileName;

            }
            return "";
        }
Пример #21
0
        private string FindByUserPrompt(FileDialog dialog, string name, string keyName, bool manual = false)
        {
            Log.File("Prompting user for {0}'s path.", name);
            MessageBox.Show(string.Format("Please select {0}'s location.", name));

            var dlgResult = dialog.ShowDialog();
            if (dlgResult == DialogResult.OK)
            {
                var path = Path.GetDirectoryName(dialog.FileName);
                Log.File("User {2}changed {0} directory to '{1}'", name, path, manual ? "manually " : " ");

                if (!TryAllStoresSetPath(keyName, path))
                    Log.Dual(Localization.FailedToSavePath, path, keyName);

                return path;
            }

            return null;
        }
Пример #22
0
 private string ShowFileDialog(FileDialog dialog)
 {
     string file = string.Empty;
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         file = dialog.FileName;
     }
     return file;
 }
Пример #23
0
 public DialogResult ShowDialog()
 {
     return(m_dlg.ShowDialog());
 }
Пример #24
0
 void DialogFileAction(FileDialog dialog, ModelAction action)
 {
     dialog.Filter = "XML Files (*.xml) | *.xml | All Files (*.*) | *.*";
     dialog.FilterIndex = 1;
     dialog.RestoreDirectory = true;
     if(dialog.ShowDialog() == DialogResult.OK)
     {
         fileName = dialog.FileName;
         CallModel(action);
     }
 }
Пример #25
0
        /// <summary>
        /// Shows the built in WinForms file dialog instead of the custom dialog. This is because of an
        /// incompatibility in Windows 8.</summary>
        /// <param name="dialog">The instance of the dialog to show</param>
        /// <param name="owner">Dialog owner</param>
        /// <returns>The DialogResult from the file dialog</returns>
        internal protected virtual DialogResult ShowNonCustomDialogInternal(FileDialog dialog, IWin32Window owner)
        {
            // Initialize the dialog settings
            dialog.Filter = m_filter;
            dialog.FilterIndex = m_filterIndex;

            if (!string.IsNullOrEmpty(m_forcedInitialDir))
            {
                dialog.InitialDirectory = m_forcedInitialDir;
            }
            else
            {
                dialog.InitialDirectory = GetLastDirForFilter(m_filter);
            }
            dialog.FileName = m_fileName;
            dialog.Title = m_title;
            
            dialog.CheckFileExists = CheckFileExists;
            dialog.CheckPathExists = CheckPathExists;
            dialog.DereferenceLinks = DereferenceLinks;
            dialog.RestoreDirectory = RestoreDirectory;
            dialog.ValidateNames = ValidateNames;

            if (m_addExt)
            {
                dialog.DefaultExt = m_defaultExt;
            }

            DialogResult result = dialog.ShowDialog(owner);

            if (result == DialogResult.OK)
            {
                // Copy the results back from the dialog.
                m_filterIndex = dialog.FilterIndex;
                if (dialog.FileNames.Length > 1)
                {
                    m_fileNames = new string[dialog.FileNames.Length];
                    for (int i = 0; i < dialog.FileNames.Length; i++)
                    {
                        m_fileNames[i] = dialog.FileNames[i];
                    }
                    m_fileName = m_fileNames[0];
                }
                else
                {
                    m_fileName = dialog.FileName;
                    m_fileNames = new string[] { m_fileName };
                }

                SetLastDirForFilter(m_filter, m_fileName);
            }
            return result;
        }
Пример #26
0
 void ShowOpenDialog(FileDialog dialog, string title, CancelEventHandler eventH)
 {
     dialog.Title = title;
       dialog.FileOk += eventH;
       dialog.ShowDialog();
       dialog.Title = "";
       dialog.FileOk -= eventH;
 }
Пример #27
0
 private void OpenDatabaseFromDialog(FileDialog fileDialog)
 {
     if(CommitChangesCancellable() == DialogResult.Cancel) {
         return;
     }
     db.RollBackChangeSet();
     if(fileDialog.ShowDialog() == DialogResult.OK) {
         LoadDatabase(fileDialog.FileName);
     }
 }
Пример #28
0
        private void PromptDialog(FileDialog dialog)
        {
            // Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            dialog.InitialDirectory = Directory.GetParent("../../").FullName;

            while (dialog.ShowDialog() != DialogResult.OK)
            {
                Console.WriteLine("You have to select a file, try again.");
            }
        }
Пример #29
0
        private void handleDialog(FileDialog fileDialog)
        {
            // Default file extension
            fileDialog.DefaultExt = "*.*";

            // Available file extensions
            fileDialog.Filter = "file Allfiles (*.*)|*.*";

            // Adds a extension if the user does not
            fileDialog.AddExtension = true;

            // Restores the selected directory, next time
            fileDialog.RestoreDirectory = true;

            // Dialog title
            fileDialog.Title = "Geef de locatie van het bestand op";

            // Startup directory
            fileDialog.InitialDirectory = @"C:/";

            fileDialog.ShowDialog();

            extractStrings(fileDialog);
        }
Пример #30
0
        /// <summary>
        /// Shows a FileDialog with the initial view set to Thumbnails.
        /// </summary>
        /// <param name="ofd">The FileDialog to show.</param>
        /// <remarks>
        /// This method may or may not show the OpenFileDialog with the initial view set to Thumbnails,
        /// depending on the implementation and available feature set of the underlying operating system
        /// or shell.
        /// Note to implementors: This method may be implemented to simply call fd.ShowDialog(owner).
        /// </remarks>
        public static DialogResult ShowFileDialogWithThumbnailView(Control owner, FileDialog fd)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            if (fd == null)
            {
                throw new ArgumentNullException("fd");
            }

            // Bug 1495: Since we do a little 'hackery' to get Thumbnails to be the default view,
            // and since the shortcut for File->Save As is Ctrl+Shift+S, and since Explorer hides
            // the filenames if you hold down Shift when opening a folder in Thumbnail view, we
            // simply spin until the user lets go of shift!
            Cursor.Current = Cursors.WaitCursor;

            while ((Control.ModifierKeys & Keys.Shift) != 0)
            {
                System.Threading.Thread.Sleep(1);
                Application.DoEvents();
            }

            Cursor.Current = Cursors.Default;

            if (owner.IsHandleCreated)
            {
                owner.BeginInvoke(new EtvDelegate(EnableThumbnailView), new object[] { fd });
            }

            DialogResult result = fd.ShowDialog(owner);
            return result;
        }
Пример #31
0
 private string showFileDialog(FileDialog dialog)
 {
     dialog.InitialDirectory = Directory.GetCurrentDirectory();
     dialog.Filter = dialogFilter;
     dialog.FileName = character.Name;
     if (dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel)
         return null;
     return dialog.FileName;
 }
Пример #32
0
        private void dinfis_Click(object sender, EventArgs e)
        {
            bfisierApasat = true; // am apasat pe din fisier
            umpleFisier = true; // umplem poligon din fisier
            lvarfuri.Enabled = false;
            numere.Enabled = false;

            // nu putem umple cu scanline
            scanLineToolStripMenuItem.Enabled = false;
            //umple.Enabled = true;
            umpleGeneratBound8 = false;
            umpleGeneratBound4 = false;
            umpleGeneratScan = false;

            // deschidem un file dialog
            preiaPoli = new OpenFileDialog();
            preiaPoli.InitialDirectory = @"E:\";
            preiaPoli.Filter = "Image Files(*.PNG;*.JPG;*.GIF)|*.PNG;*.JPG;*.GIF";

            if (preiaPoli.ShowDialog() == DialogResult.OK)
            {
                Image img = Image.FromFile(preiaPoli.FileName); // preluam efectiv imaginea
                poligonFisier = new Bitmap(img);

                pictureBox1.Image = poligonFisier;
                // punem imaginea in centrul picture box
                // pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage; asta face o translatie si nu mai
                // e vazuta ok pozitia mouse-ului

            }
        }
Пример #33
0
 private static void SelectFile(FileDialog dialog, Action<string> continuation)
 {
     dialog.Filter = "Config Files|*." + Settings.Default.ConfigurationFileExtension;
     if (dialog.ShowDialog() == DialogResult.OK)
         continuation(dialog.FileName);
 }
Пример #34
0
        private void salveazaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            preiaPoli = new SaveFileDialog();
            preiaPoli.InitialDirectory = @"E:\";
            preiaPoli.Title = "Salveaza poligonul";
            preiaPoli.DefaultExt = ".PNG";
            preiaPoli.CheckPathExists = true;
            preiaPoli.Filter = "Image Files(*.PNG;*.JPG;*.GIF)|*.PNG;*.JPG;*.GIF";

            if (preiaPoli.ShowDialog() == DialogResult.OK)
            {
                pictureBox1.Image.Save(preiaPoli.FileName);
                MessageBox.Show("Imagine salvata cu succes");
            }
            else if (preiaPoli.ShowDialog() == DialogResult.Cancel)
            {
                pictureBox1.Image = null;
                genereaza.Enabled = true;
                numere.Enabled = true;
                numere.Visible = true;
            }
        }
Пример #35
0
 private void Button2Click(object sender, EventArgs e)
 {
     _dialog = new SaveFileDialog();
     if (_dialog.ShowDialog() == DialogResult.OK)
         textBox2.Text = _dialog.FileName;
 }
        private void ShowFileDialog(
                     FileDialog dialog,
                     string successMessage,
                     string failureMessage,
                     Predicate<string> filePredicate)
        {
            try
            {
                dialog.DefaultExt = "xml";
                dialog.AddExtension = true;
                dialog.Filter = "(*.xml)|*.xml";
                DialogResult result = dialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    string file = dialog.FileName;
                    bool success = filePredicate(file);

                    if (success == true)
                        MessageBox.Show(
                             string.Format(CultureInfo.CurrentCulture,
                                                successMessage,
                                                file));
                    else
                        MessageBox.Show(failureMessage);
                }
            }
            catch (Exception ex)
            {
                Utilities.HandleException(ex);
            }
        }
Пример #37
0
		public DialogResult ShowDialog(IWin32Window owner)
		{
			DialogResult returnDialogResult = DialogResult.Cancel;
			if (this.IsDisposed)
				return returnDialogResult;
			if (owner == null || owner.Handle == IntPtr.Zero)
			{
				WindowWrapper wr = new WindowWrapper(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
				owner = wr;
			}
			OriginalCtrlSize = this.Size;
			_MSdialog = (FileDlgType == FileDialogType.OpenFileDlg)?new OpenFileDialog()as FileDialog:new SaveFileDialog() as FileDialog;
			_dlgWrapper = new WholeDialogWrapper(this);
			OnPrepareMSDialog();
			if (!_hasRunInitMSDialog)
				InitMSDialog();
			try
			{
				System.Reflection.PropertyInfo AutoUpgradeInfo = MSDialog.GetType().GetProperty("AutoUpgradeEnabled");
				if (AutoUpgradeInfo != null)
					AutoUpgradeInfo.SetValue(MSDialog, false, null);
				returnDialogResult = _MSdialog.ShowDialog(owner);
			}
			// Sometimes if you open a animated .gif on the preview and the Form is closed, .Net class throw an exception
			// Lets ignore this exception and keep closing the form.
			catch (ObjectDisposedException)
			{
			}
			catch (Exception ex)
			{
				MessageBox.Show("unable to get the modal dialog handle", ex.Message);
			}
			return returnDialogResult;
		}
Пример #38
0
 private bool FileBrowse(FileDialog dialog)
 {
     // ༼ つ ◕_◕ ༽つ IMPEACH STAThread ༼ つ ◕_◕ ༽つ
     var wait = new AutoResetEvent(false);
     bool success = false;
     var thread = new Thread(() => {
         success = DialogResult.OK == dialog.ShowDialog();
         wait.Set();
     });
     thread.SetApartmentState(ApartmentState.STA);
     thread.Start();
     wait.WaitOne();
     return success;
 }
Пример #39
0
        bool DialogCancelled(FileDialog dialog)
        {
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return true;
            }

            fileName = dialog.FileName;
            Text = fileName;

            return false;
        }
Пример #40
0
 public string ShowFileDialog(FileDialog dialog, string title, string filepattern, bool CheckFileExists = true)
 {
     dialog.Title = title;
     dialog.Filter = filepattern;
     dialog.CheckFileExists = CheckFileExists;
     if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         return dialog.FileName;
     else
         return string.Empty;
 }