示例#1
0
        protected override bool RunDialog(IntPtr hWndOwner)
        {
            bool flag;

            System.Windows.Forms.NativeMethods.WndProc    proc = new System.Windows.Forms.NativeMethods.WndProc(this.HookProc);
            System.Windows.Forms.NativeMethods.CHOOSEFONT cf   = new System.Windows.Forms.NativeMethods.CHOOSEFONT();
            IntPtr dC = System.Windows.Forms.UnsafeNativeMethods.GetDC(System.Windows.Forms.NativeMethods.NullHandleRef);

            System.Windows.Forms.NativeMethods.LOGFONT logFont = new System.Windows.Forms.NativeMethods.LOGFONT();
            Graphics graphics = Graphics.FromHdcInternal(dC);

            System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
            try
            {
                this.Font.ToLogFont(logFont, graphics);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
                graphics.Dispose();
            }
            System.Windows.Forms.UnsafeNativeMethods.ReleaseDC(System.Windows.Forms.NativeMethods.NullHandleRef, new HandleRef(null, dC));
            IntPtr zero = IntPtr.Zero;

            try
            {
                zero = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.LOGFONT)));
                Marshal.StructureToPtr(logFont, zero, false);
                cf.lStructSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.CHOOSEFONT));
                cf.hwndOwner   = hWndOwner;
                cf.hDC         = IntPtr.Zero;
                cf.lpLogFont   = zero;
                cf.Flags       = (this.Options | 0x40) | 8;
                if ((this.minSize > 0) || (this.maxSize > 0))
                {
                    cf.Flags |= 0x2000;
                }
                if (this.ShowColor || this.ShowEffects)
                {
                    cf.rgbColors = ColorTranslator.ToWin32(this.color);
                }
                else
                {
                    cf.rgbColors = ColorTranslator.ToWin32(System.Drawing.Color.Black);
                }
                cf.lpfnHook  = proc;
                cf.hInstance = System.Windows.Forms.UnsafeNativeMethods.GetModuleHandle(null);
                cf.nSizeMin  = this.minSize;
                if (this.maxSize == 0)
                {
                    cf.nSizeMax = 0x7fffffff;
                }
                else
                {
                    cf.nSizeMax = this.maxSize;
                }
                if (!System.Windows.Forms.SafeNativeMethods.ChooseFont(cf))
                {
                    return(false);
                }
                System.Windows.Forms.NativeMethods.LOGFONT logfont2 = null;
                logfont2 = (System.Windows.Forms.NativeMethods.LOGFONT)System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(zero, typeof(System.Windows.Forms.NativeMethods.LOGFONT));
                if ((logfont2.lfFaceName != null) && (logfont2.lfFaceName.Length > 0))
                {
                    logFont = logfont2;
                    this.UpdateFont(logFont);
                    this.UpdateColor(cf.rgbColors);
                }
                flag = true;
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(zero);
                }
            }
            return(flag);
        }
 protected override bool RunDialog(IntPtr hWndOwner)
 {
     bool flag;
     System.Windows.Forms.NativeMethods.WndProc proc = new System.Windows.Forms.NativeMethods.WndProc(this.HookProc);
     System.Windows.Forms.NativeMethods.CHOOSEFONT cf = new System.Windows.Forms.NativeMethods.CHOOSEFONT();
     IntPtr dC = System.Windows.Forms.UnsafeNativeMethods.GetDC(System.Windows.Forms.NativeMethods.NullHandleRef);
     System.Windows.Forms.NativeMethods.LOGFONT logFont = new System.Windows.Forms.NativeMethods.LOGFONT();
     Graphics graphics = Graphics.FromHdcInternal(dC);
     System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
     try
     {
         this.Font.ToLogFont(logFont, graphics);
     }
     finally
     {
         CodeAccessPermission.RevertAssert();
         graphics.Dispose();
     }
     System.Windows.Forms.UnsafeNativeMethods.ReleaseDC(System.Windows.Forms.NativeMethods.NullHandleRef, new HandleRef(null, dC));
     IntPtr zero = IntPtr.Zero;
     try
     {
         zero = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.LOGFONT)));
         Marshal.StructureToPtr(logFont, zero, false);
         cf.lStructSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.CHOOSEFONT));
         cf.hwndOwner = hWndOwner;
         cf.hDC = IntPtr.Zero;
         cf.lpLogFont = zero;
         cf.Flags = (this.Options | 0x40) | 8;
         if ((this.minSize > 0) || (this.maxSize > 0))
         {
             cf.Flags |= 0x2000;
         }
         if (this.ShowColor || this.ShowEffects)
         {
             cf.rgbColors = ColorTranslator.ToWin32(this.color);
         }
         else
         {
             cf.rgbColors = ColorTranslator.ToWin32(System.Drawing.Color.Black);
         }
         cf.lpfnHook = proc;
         cf.hInstance = System.Windows.Forms.UnsafeNativeMethods.GetModuleHandle(null);
         cf.nSizeMin = this.minSize;
         if (this.maxSize == 0)
         {
             cf.nSizeMax = 0x7fffffff;
         }
         else
         {
             cf.nSizeMax = this.maxSize;
         }
         if (!System.Windows.Forms.SafeNativeMethods.ChooseFont(cf))
         {
             return false;
         }
         System.Windows.Forms.NativeMethods.LOGFONT logfont2 = null;
         logfont2 = (System.Windows.Forms.NativeMethods.LOGFONT) System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(zero, typeof(System.Windows.Forms.NativeMethods.LOGFONT));
         if ((logfont2.lfFaceName != null) && (logfont2.lfFaceName.Length > 0))
         {
             logFont = logfont2;
             this.UpdateFont(logFont);
             this.UpdateColor(cf.rgbColors);
         }
         flag = true;
     }
     finally
     {
         if (zero != IntPtr.Zero)
         {
             Marshal.FreeCoTaskMem(zero);
         }
     }
     return flag;
 }
 public static extern bool ChooseFont([In, Out] System.Windows.Forms.NativeMethods.CHOOSEFONT cf);