Converting System.Windows.Media.Color to System.Drawing.Color
Asked Answered
S

2

40
private void DialogFont_Load(object sender, EventArgs e)
{
    LoadInstalledFonts();
    SetupInitialDialogSelections();
    lblPreview.ForeColor = colorPicker1.colorPickerControlView1.CurrentColor.Color;
}

I'd like to convert the value to a System.Drawing.Color.

Any ideas?

Sanitize answered 6/1, 2011 at 14:12 Comment(0)
C
72
System.Windows.Media.Color mediacolor; // your color

var drawingcolor = System.Drawing.Color.FromArgb(
    mediacolor.A, mediacolor.R, mediacolor.G, mediacolor.B);
Ciro answered 6/1, 2011 at 14:16 Comment(0)
T
5

Just for reference... I use this:

using System.Runtime.CompilerServices;
using System.Windows.Media;

namespace HQ.Wpf.Util
{
    public static class ColorExtension
    {
        /// <summary>
        /// Convert Media Color (WPF) to Drawing Color (WinForm)
        /// </summary>
        /// <param name="mediaColor"></param>
        /// <returns></returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static System.Drawing.Color ToDrawingColor(this System.Windows.Media.Color mediaColor)
        {
            return System.Drawing.Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B);
        }

        /// <summary>
        /// Convert Drawing Color (WPF) to Media Color (WinForm)
        /// </summary>
        /// <param name="drawingColor"></param>
        /// <returns></returns>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static System.Windows.Media.Color ToMediaColor(this System.Drawing.Color drawingColor)
        {
            return System.Windows.Media.Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B);
        }
Tubman answered 10/7, 2020 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.