Converting System.Windows.Media.Color to System.Drawing.Color

后端 未结 2 1879
独厮守ぢ
独厮守ぢ 2020-12-17 08:08
private void DialogFont_Load(object sender, EventArgs e)
{
    LoadInstalledFonts();
    SetupInitialDialogSelections();
    lblPreview.ForeColor = colorPicker1.colo         


        
相关标签:
2条回答
  • 2020-12-17 08:33
    System.Windows.Media.Color mediacolor; // your color
    
    var drawingcolor = System.Drawing.Color.FromArgb(
        mediacolor.A, mediacolor.R, mediacolor.G, mediacolor.B);
    
    0 讨论(0)
  • 2020-12-17 08:47

    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);
            }
    
    0 讨论(0)
提交回复
热议问题