New() public méthode

Create a new object of a named type passing along any params
public New ( string name ) : object
name string The name of the type to create
Résultat object
Exemple #1
0
        /// <summary>
        ///     Shows the dialog
        /// </summary>
        /// <param name="hWndOwner">Handle of the control to be parent</param>
        /// <returns>True if the user presses OK else false</returns>
        public bool ShowDialog(IntPtr hWndOwner)
        {
            bool flag;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                var r = new Reflector("System.Windows.Forms");

                uint num             = 0;
                var  typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
                var  dialog          = r.Call(_ofd, "CreateVistaDialog");
                r.Call(_ofd, "OnBeforeVistaDialog", dialog);

                var options = (uint)r.CallAs(typeof(FileDialog), _ofd, "GetOptions");
                options |= (uint)r.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
                r.CallAs(typeIFileDialog, dialog, "SetOptions", options);

                var      pfde       = r.New("FileDialog.VistaDialogEvents", _ofd);
                object[] parameters = { pfde, num };
                r.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
                num = (uint)parameters[1];
                try
                {
                    var num2 = (int)r.CallAs(typeIFileDialog, dialog, "Show", hWndOwner);
                    flag = 0 == num2;
                }
                finally
                {
                    r.CallAs(typeIFileDialog, dialog, "Unadvise", num);
                    GC.KeepAlive(pfde);
                }
            }
            else
            {
                var fbd = new FolderBrowserDialog
                {
                    Description         = Title,
                    SelectedPath        = InitialDirectory,
                    ShowNewFolderButton = false
                };

                if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK)
                {
                    return(false);
                }
                _ofd.FileName = fbd.SelectedPath;
                flag          = true;
            }

            return(flag);
        }
        /// <summary>
        /// Shows the dialog
        /// </summary>
        /// <param name="hWndOwner">Handle of the control to be parent</param>
        /// <returns>True if the user presses OK else false</returns>
        public bool ShowDialog(IntPtr hWndOwner)
        {
            bool flag = false;

            //if (Environment.OSVersion.Version.Major >= 6)
            //{
            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);
            }

            /*}
             * else
             * {
             *      var fbd = new FolderBrowserDialog();
             *      fbd.Description = this.Title;
             *      fbd.SelectedPath = this.InitialDirectory;
             *      fbd.ShowNewFolderButton = false;
             *      if (fbd.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK) return false;
             *      ofd.FileName = fbd.SelectedPath;
             *      flag = true;
             * }*/

            return(flag);
        }
        /// <summary>
        /// Shows the dialog
        /// </summary>
        /// <param name="hWndOwner">Handle of the control to be parent</param>
        /// <returns>True if the user presses OK else false</returns>
        public bool ShowDialog(IntPtr hWndOwner)
        {
            bool flag = false;

            if (PlatformHelper.GetPlatform() == Platform.OsX ||
                PlatformHelper.GetPlatform() == Platform.Linux ||
                Environment.OSVersion.Version.Major < 6)
            {
                flag = FallBackToFolderBrowserDialog(hWndOwner);
            }
            else
            {
                var r = new Reflector("System.Windows.Forms");

                uint num             = 0;
                Type typeIFileDialog = r.GetType("FileDialogNative.IFileDialog");
                if (typeIFileDialog == null)
                {
                    flag = FallBackToFolderBrowserDialog(hWndOwner);
                }
                else
                {
                    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);
                    }
                }
            }

            return(flag);
        }
Exemple #4
0
        public bool ShowDialog(IntPtr hWndOwner)
        {
            if ((Environment.OSVersion.Version.Major >= 6) && !this.UseOldDialog)
            {
                var    reflector = new Reflector("System.Windows.Forms");
                uint   num       = 0;
                var    type      = reflector.GetType("FileDialogNative.IFileDialog");
                object obj2      = reflector.Call(this.ofd, "CreateVistaDialog", new object[0]);
                reflector.Call(this.ofd, "OnBeforeVistaDialog", new object[] { obj2 });
                uint num2 = (uint)reflector.CallAs(typeof(FileDialog), this.ofd, "GetOptions", new object[0]);
                num2 |= (uint)reflector.GetEnum("FileDialogNative.FOS", "FOS_PICKFOLDERS");
                reflector.CallAs(type, obj2, "SetOptions", new object[] { num2 });
                object   obj3       = reflector.New("FileDialog.VistaDialogEvents", new object[] { this.ofd });
                object[] parameters = new object[] { obj3, num };
                reflector.CallAs2(type, obj2, "Advise", parameters);
                num = (uint)parameters[1];
                try
                {
                    int num3 = (int)reflector.CallAs(type, obj2, "Show", new object[] { hWndOwner });
                    return(0 == num3);
                }
                finally
                {
                    reflector.CallAs(type, obj2, "Unadvise", new object[] { num });
                    GC.KeepAlive(obj3);
                }
            }
            var ex = new FolderBrowserDialogEx();

            ex.Description           = this.Title;
            ex.SelectedPath          = this.InitialDirectory;
            ex.ShowNewFolderButton   = true;
            ex.ShowEditBox           = true;
            ex.ShowFullPathInEditBox = true;
            if (ex.ShowDialog(new WindowWrapper(hWndOwner)) != DialogResult.OK)
            {
                return(false);
            }
            ofd.FileName = ex.SelectedPath;
            return(true);
        }
        /// <summary>
        /// Shows the dialog
        /// </summary>
        /// <param name="hWndOwner">Handle of the control to be parent</param>
        /// <returns>True if the user presses OK else false</returns>
        public bool ShowDialog(IntPtr hWndOwner)
        {
            bool flag = false;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                //try {
                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);
                }
                //} catch {
                //	flag = oldFileBrowser(hWndOwner, flag);
                //}
            }
            else
            {
                flag = oldFileBrowser(hWndOwner, flag);
            }

            return(flag);
        }
Exemple #6
0
        /// <summary>Runs a common dialog box modally with the specified owner.</summary>
        /// <param name="owner">Any object that implements IWin32Window that represents
        ///     the top-level window that will own the modal dialog box.</param>
        /// <returns>DialogResult.OK if the user clicks OK in the dialog box; DialogResult.Cancel otherwise.</returns>
        public virtual DialogResult ShowDialog(IWin32Window owner)
        {
            /* Quote from the original post:
             *  Being a Vista-style dialog box the dialog can only be shown on Vista or later (not WinNT, XP or 2003).
             *  The code gracefully reverts to show the old-style dialog if OS is not major version 6 or later.
             */
            if (Environment.OSVersion.Version.Major >= 6)
            {
                uint   num             = 0;
                Type   typeIFileDialog = reflector.GetType("FileDialogNative.IFileDialog");
                object dialog          = reflector.Call(this.dialog, "CreateVistaDialog");
                reflector.Call(this.dialog, "OnBeforeVistaDialog", dialog);

                if (this.shouldSetOptions)
                {
                    uint options = (uint)reflector.CallAs(typeof(FileDialog), this.dialog, "GetOptions");
                    this.SetOptions(ref options);
                    reflector.CallAs(typeIFileDialog, dialog, "SetOptions", options);
                }

                object   pfde       = reflector.New("FileDialog.VistaDialogEvents", this.dialog);
                object[] parameters = new object[] { pfde, num };
                reflector.CallAs2(typeIFileDialog, dialog, "Advise", parameters);
                num = (uint)parameters[1];

                try     {
                    var result = (int)reflector.CallAs(typeIFileDialog, dialog, "Show", owner?.Handle ?? IntPtr.Zero);
                    return(result == 0 ? DialogResult.OK : DialogResult.Cancel);
                } finally {
                    reflector.CallAs(typeIFileDialog, dialog, "Unadvise", num);
                    GC.KeepAlive(pfde);
                }
            }
            else
            {
                return(this.ShowDialogFallback(owner));
            }
        }