/// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.Windows.Forms.Control" /> and its child controls and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing"><see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            if (MSDialog != null)
            {
                MSDialog.FileOk -= new CancelEventHandler(DialogClosing);

                MSDialog.Disposed -= new EventHandler(DialogDisposed);

                MSDialog.HelpRequest -= new EventHandler(HelpRequest);

                MSDialog.Dispose();

                MSDialog = null;
            }

            if (disposing && (components != null))
            {
                components.Dispose();
            }

            base.Dispose(disposing);
        }
Пример #2
0
 protected override void OnPrepareMSDialog()
 {
     base.FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
     if (Environment.OSVersion.Version.Major < 6)
     {
         MSDialog.SetPlaces(new object[] { @"c:\", (int)Places.MyComputer, (int)Places.Favorites, (int)Places.Printers, (int)Places.Fonts, });
     }
     base.OnPrepareMSDialog();
 }
Пример #3
0
 protected override void OnPrepareMSDialog()
 {
     base.OnPrepareMSDialog();
     MSDialog.FilterIndex = GetIndexfromFile(_imageFile);
     if (Environment.OSVersion.Version.Major < 6)
     {
         MSDialog.SetPlaces(new object[] { (int)Places.Desktop, (int)Places.Printers, (int)Places.Favorites, (int)Places.Programs, (int)Places.Fonts, });
     }
     FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
 }
        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)
            {
                _eh.ThrowException(MessageBoxIcon.Error, $"Unable to get the modal dialog handle: { ex.Message }", "Error", MessageBoxButtons.OK);
            }
            return(returnDialogResult);
        }
Пример #5
0
        protected override void OnPrepareMSDialog()
        {
            //Default yugi directory with fallback
            base.FileDlgInitialDirectory = YuGiExtendedMethods.GetDefaultGamePath()[0];//Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            base.FileDlgShowHelp         = false;
            base.FileDlgMultiselect      = true;

            //base.FileDlgFileNames
            //base.
            if (Environment.OSVersion.Version.Major < 6)
            {
                MSDialog.SetPlaces(new object[] { @"c:\", (int)Places.MyComputer, (int)Places.Favorites, (int)Places.Printers, (int)Places.Fonts, });
            }
            base.OnPrepareMSDialog();
        }
Пример #6
0
 private void InitMSDialog()
 {
     System.Reflection.PropertyInfo AutoUpgradeInfo = MSDialog.GetType().GetProperty("AutoUpgradeEnabled");
     if (AutoUpgradeInfo != null)
     {
         AutoUpgradeInfo.SetValue(MSDialog, false, null);
     }
     MSDialog.InitialDirectory = _InitialDirectory.Length == 0 ? Path.GetDirectoryName(Application.ExecutablePath) : _InitialDirectory;
     MSDialog.AddExtension     = _AddExtension;
     MSDialog.Filter           = _Filter;
     MSDialog.FilterIndex      = _FilterIndex;
     MSDialog.CheckFileExists  = _CheckFileExists;
     MSDialog.DefaultExt       = _DefaultExt;
     MSDialog.FileName         = _FileName;
     MSDialog.DereferenceLinks = _DereferenceLinks;
     MSDialog.ShowHelp         = _ShowHelp;
     _hasRunInitMSDialog       = true;
 }
Пример #7
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     if (IsDisposed)
     {
         return;
     }
     if (MSDialog != null)
     {
         MSDialog.FileOk   -= new System.ComponentModel.CancelEventHandler(FileDialogControlBase_ClosingDialog);
         MSDialog.Disposed -= new EventHandler(FileDialogControlBase_DialogDisposed);
         //if (MSDialog.ShowHelp)
         MSDialog.HelpRequest -= new EventHandler(FileDialogControlBase_HelpRequest);
         MSDialog.Dispose();
         MSDialog = null;
     }
     if (disposing && (components != null))
     {
         components.Dispose();
     }
     base.Dispose(disposing);
 }
Пример #8
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;

            // Tried to port vista filedialog...
            //CustomCon
            //var r = new  Reflector("System.Windows.Forms");

            //uint num = 0;
            //Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
            //object dialog = r.Call(ofd, "CreateVistaDialog");
            //r.Call(ofd, "OnBeforeVistaDialog", dialog);

            //uint options = (uint)r.CallAs(typeof(System.Windows.Forms.FileDialog), ofd, "GetOptions");
            //options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
            //r.CallAs(typeIFileDialog, dialog, "SetOptions", options);

            //object pfde = r.New("FileDialog.VistaDialogEvents", ofd);
            //object[] parameters = new object[] { pfde, num };
            //r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
            //num = (uint)parameters[1];
            //try
            //{
            //    int num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner);
            //    flag = 0 == num2;
            //}
            //finally
            //{
            //    r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
            //    GC.KeepAlive(pfde);
            //}

            _MSdialog = new OpenFileDialog();
            _MSdialog.AutoUpgradeEnabled = true;
            _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);
        }