Example #1
0
        /* private static void BlockPrintScreen(Form f, bool bBlock)
         * {
         *      if(f == null) { Debug.Assert(false); return; }
         *
         *      try
         *      {
         *              if(bBlock)
         *              {
         *                      NativeMethods.RegisterHotKey(f.Handle, NativeMethods.IDHOT_SNAPDESKTOP,
         *                              0, NativeMethods.VK_SNAPSHOT);
         *                      NativeMethods.RegisterHotKey(f.Handle, NativeMethods.IDHOT_SNAPWINDOW,
         *                              NativeMethods.MOD_ALT, NativeMethods.VK_SNAPSHOT);
         *              }
         *              else
         *              {
         *                      NativeMethods.UnregisterHotKey(f.Handle, NativeMethods.IDHOT_SNAPWINDOW);
         *                      NativeMethods.UnregisterHotKey(f.Handle, NativeMethods.IDHOT_SNAPDESKTOP);
         *              }
         *      }
         *      catch(Exception) { Debug.Assert(false); }
         * } */

        internal static DialogResult ShowDialog <TForm, TResult>(bool bProtect,
                                                                 GFunc <TForm> fnConstruct, GFunc <TForm, TResult> fnResultBuilder,
                                                                 out TResult r)
            where TForm : Form
            where TResult : class
        {
            if (fnConstruct == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("fnConstruct");
            }
            if (fnResultBuilder == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("fnResultBuilder");
            }

            r = null;

            if (!bProtect)
            {
                TForm tf = fnConstruct();
                if (tf == null)
                {
                    Debug.Assert(false); return(DialogResult.None);
                }

                try
                {
                    DialogResult drDirect = tf.ShowDialog();
                    r = fnResultBuilder(tf);                     // Always
                    return(drDirect);
                }
                finally { UIUtil.DestroyForm(tf); }
            }

            UIFormConstructor fnUifC = delegate(object objParam)
            {
                return(fnConstruct());
            };

            UIFormResultBuilder fnUifRB = delegate(Form f)
            {
                TForm tf = (f as TForm);
                if (tf == null)
                {
                    Debug.Assert(false); return(null);
                }

                return(fnResultBuilder(tf));
            };

            ProtectedDialog dlg = new ProtectedDialog(fnUifC, fnUifRB);

            object       objResult;
            DialogResult dr = dlg.ShowDialog(out objResult, null);

            r = (objResult as TResult);
            return(dr);
        }
        public ProtectedDialog(UIFormConstructor fnConstruct,
            UIFormResultBuilder fnResultBuilder)
        {
            if(fnConstruct == null) { Debug.Assert(false); throw new ArgumentNullException("fnConstruct"); }
            if(fnResultBuilder == null) { Debug.Assert(false); throw new ArgumentNullException("fnResultBuilder"); }

            m_fnConstruct = fnConstruct;
            m_fnResultBuilder = fnResultBuilder;
        }
Example #3
0
        public ProtectedDialog(UIFormConstructor fnConstruct,
                               UIFormResultBuilder fnResultBuilder)
        {
            if (fnConstruct == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("fnConstruct");
            }
            if (fnResultBuilder == null)
            {
                Debug.Assert(false); throw new ArgumentNullException("fnResultBuilder");
            }

            m_fnConstruct     = fnConstruct;
            m_fnResultBuilder = fnResultBuilder;
        }