How can shou implement inline color code in a WinForm application?

I am creating a WinForms application and I use certain colors for most controls. I sometimes do this from the WinForms constructor, and sometimes directly into my code.

I have a static class that looks like this:

 public static class MyColors
    {
        public static Color DarkGreen = Color.FromArgb(0, 70, 62);
        ...
        public static Color Orange = Color.FromArgb(239, 132, 16);

    }

I can easily use these colors in my code, but this cannot be done from the constructor, which causes this error:

MyColors.DarkGreen invalid value for Int32.

(I tried to keep the Int32 representation of these colors, but this is not with the same error)

, , rgb , MyColors , , Visual Studio. , .

?


. , , "KnownColors".

+5
5

, , , , Color editor, , , , , Editor .

, - TypeConverter TypeConverterAttribute.

+2

, , . "255, 128, 64" , "" , , , "-", RGB, "-- Int32." , (, "MyColors.DarkGreen" ).

+2

, , . .

, , , . ​​ RGB ; , ( ), . .

, . .

, , . , .

, , , , , .

:

 public static class MyColors
    {
        public static Color DarkGreen = Color.FromArgb(0, 70, 62);
        ...
        public static Color Orange = Color.FromArgb(239, 132, 16);

        public static Color ButtonBackColor = DarkGreen;
    }

, DarkGreen Orange, .

+1

, backcolor forecolor, , :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace YourNameSpace
{
    public partial class NameOfStaticColoredLabel : Label
    {
        public NameOfStaticColoredLabel()
        {
            InitializeComponent();
        }

        public NameOfStaticColoredLabel(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        public override Color ForeColor
        {
            get
            {
                return Color.Black;
            }
            set
            {
                base.ForeColor = Color.Black;
            }
        }

        public override Color BackColor
        {
            get
            {
                return Color.Aquamarine;
            }
            set
            {
                base.BackColor = Color.Aquamarine;
            }
        }
    }
}

, , . . , . , .

+1

, . , , .

public static Color DarkGreen = Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(70)))), ((int)(((byte)(62)))));
0

All Articles