/// <summary>
        /// Displays a <see cref="CustomColorDialog"/> in front of the specified WPF <see
        /// cref="WpfWindow"/> and with the specified WPF color initially selected.</summary>
        /// <param name="owner">
        /// A WPF <see cref="WpfWindow"/> indicating the parent window of the dialog.</param>
        /// <param name="color"><para>
        /// The initially selected <see cref="WpfColor"/>. <see cref="WpfColors.Transparent"/>
        /// translates to <see cref="WpfColors.Black"/>.
        /// </para><para>
        /// On return, contains the current color selection if the dialog was dismissed by clicking
        /// <b>OK</b>; otherwise unchanged.</para></param>
        /// <returns>
        /// <c>true</c> if the <see cref="CustomColorDialog"/> was dismissed with a <see
        /// cref="DialogResult"/> of <see cref="DialogResult.OK"/>; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks><para>
        /// If the <see cref="CustomColorDialog"/> was dismissed by clicking <b>OK</b>, <b>Show</b>
        /// stores the current color selection in the <paramref name="color"/> argument.
        /// </para><para>
        /// The current set of <see cref="ColorDialog.CustomColors"/> is stored in the static <see
        /// cref="CustomColorSet"/> property so that it can be restored when the next instance of
        /// the <b>CustomColorDialog</b> class is created.</para></remarks>

        public static bool Show(WpfWindow owner, ref WpfColor color)
        {
            using (CustomColorDialog dialog = new CustomColorDialog(color.ToGdiColor())) {
                DialogResult result = dialog.ShowDialog(new HwndWrapper(owner));

                // retrieve selected and custom colors on OK
                if (result == DialogResult.OK)
                {
                    color = dialog.Color.ToWpfColor();
                    CustomColorDialog.CustomColorSet = dialog.CustomColors;
                }

                return(result == DialogResult.OK);
            }
        }
示例#2
0
        internal static Brush GetPreviewBrush(BrushEffect effect, System.Windows.Media.Color color, ref SizeF previewRegion)
        {
            switch (effect)
            {
            case BrushEffect.Solid:
                return(new SolidBrush(color.ToGdiColor()));

            case BrushEffect.ToBottom:
                return(new LinearGradientBrush(new PointF(0, 0), new PointF(0, previewRegion.Height), Color.Transparent, color.ToGdiColor()));

            case BrushEffect.ToTop:
                return(new LinearGradientBrush(new PointF(0, previewRegion.Height), new PointF(0, 0), Color.Transparent, color.ToGdiColor()));

            case BrushEffect.ToRight:
                return(new LinearGradientBrush(new PointF(0, 0), new PointF(previewRegion.Width, 0), Color.Transparent, color.ToGdiColor()));

            case BrushEffect.ToLeft:
                return(new LinearGradientBrush(new PointF(previewRegion.Width, 0), new PointF(0, 0), Color.Transparent, color.ToGdiColor()));

            default:
                goto case BrushEffect.Solid;
            }
        }