示例#1
0
        /// <summary>
        /// 根据颜色表示字符串获取对应的颜色
        /// </summary>
        /// <param name="colorValueString"></param>
        /// <returns></returns>
        public static Color GetColorByValue(string colorValueString)
        {
            if (colorValueString == null || colorValueString == String.Empty)
            {
                return(Color.Empty);
            }

            string[] strArray = colorValueString.Split('.');

            ChooseColorType type =
                (ChooseColorType)Convert.ToInt32(strArray[0]);
            Color color = Color.Empty;

            switch (type)
            {
            case ChooseColorType.Custom:
                color = Color.FromArgb(Convert.ToInt32(strArray[2]));
                break;

            case ChooseColorType.Define:
                color = Color.FromArgb(Convert.ToInt32(strArray[2]));
                break;

            case ChooseColorType.System:
                Type         typeSystemColors = typeof(System.Drawing.SystemColors);
                PropertyInfo p = typeSystemColors.GetProperty(strArray[1]);
                color = (Color)p.GetValue(typeSystemColors, null);
                break;
            }

            return(color);
        }
        public UIElementColor(string colorValueString)
        {
            if (colorValueString == null || colorValueString == String.Empty)
            {
                _color = Color.Empty;
            }
            else
            {
                string[]        strArray = colorValueString.Split('.');
                ChooseColorType type     =
                    (ChooseColorType)Convert.ToInt32(strArray[0]);
                Color color = Color.Empty;
                switch (type)
                {
                case ChooseColorType.Custom:
                    color = Color.FromArgb(Convert.ToInt32(strArray[2]));
                    break;

                case ChooseColorType.Define:
                    color = Color.FromArgb(Convert.ToInt32(strArray[2]));
                    break;

                case ChooseColorType.System:
                    Type         typeSystemColors = typeof(SystemColors);
                    PropertyInfo p = typeSystemColors.GetProperty(strArray[1]);
                    color = (Color)p.GetValue(typeSystemColors, null);
                    break;
                }
                _type  = type;
                _name  = strArray[1];
                _color = color;
            }
        }
        public void FromXml(string strXml)
        {
            SEXElement xmlDoc = SEXElement.Parse(strXml);

            this._name = xmlDoc.GetAttributeObject("Name");
            this._type = (ChooseColorType)xmlDoc.GetAttributeObject <int>("Type", 0);
            int a = xmlDoc.GetAttributeObject <int>("A", 0);
            int r = xmlDoc.GetAttributeObject <int>("R", 0);
            int g = xmlDoc.GetAttributeObject <int>("G", 0);
            int b = xmlDoc.GetAttributeObject <int>("B", 0);

            this._color = Color.FromArgb(a, r, g, b);
        }
        /// <summary>
        /// 定位到选中的颜色
        /// </summary>
        public void ShowCurrentTabPage()
        {
            #region 如果当前有选定颜色设置
            if (this.SelectedColorValue != null && this.SelectedColorValue != String.Empty)
            {
                //定位到选中的颜色
                ChooseColorType type =
                    (ChooseColorType)Convert.ToInt32(this.SelectedColorValue.Split('.')[0]);

                switch (type)
                {
                case ChooseColorType.Custom:

                    this.tabControl1.SelectedTab = tabPageCustom;
                    if (this.customColorBitmap == null)
                    {
                        customColorBitmap   = new Bitmap(this.picCustomColor.Width, this.picCustomColor.Height);
                        customColorGraphics = Graphics.FromImage(customColorBitmap);
                    }

                    customColorGraphics.Clear(Color.FromArgb(Convert.ToInt32(this.SelectedColorValue.Split('.')[2])));
                    customColorGraphics.DrawRectangle(Pens.Black, 0, 0, this.picCustomColor.Width - 1, this.picCustomColor.Height - 1);

                    this.picCustomColor.Image = customColorBitmap;

                    break;

                case ChooseColorType.Define:
                    this.tabControl1.SelectedTab = tabPageDefine;
                    foreach (DataGridViewRow dr in this.dataGridViewDefineColor.Rows)
                    {
                        if (dr.Cells["ColumnNameDefineColor"].Value.ToString() == this.SelectedColorValue.Split('.')[1])
                        {
                            dr.Selected = true;
                            this.dataGridViewDefineColor.FirstDisplayedScrollingRowIndex = dr.Index;
                            break;
                        }
                    }
                    break;

                case ChooseColorType.System:
                    this.tabControl1.SelectedTab = tabPageSystem;
                    foreach (DataGridViewRow dr in this.dataGridViewSystemColors.Rows)
                    {
                        if (dr.Cells["ColumnNameSystemColor"].Value.ToString() == this.SelectedColorValue.Split('.')[1])
                        {
                            dr.Selected = true;
                            this.dataGridViewSystemColors.FirstDisplayedScrollingRowIndex = dr.Index;
                            break;
                        }
                    }
                    break;
                }
            }
            #endregion
            #region 如果当前选择颜色设置为空
            else
            {
                //      this.tabControl1.SelectedTab = tabPageCustom;
            }
            #endregion
        }
 public UIElementColor(ChooseColorType type, string name, Color color)
 {
     _type  = type;
     _name  = name;
     _color = color;
 }