/// <summary> /// add color to list /// </summary> /// <param name="c">new color value</param> public void Add(Color c) { if (c.IsEmpty) return; if (c.A == 0) return; if (c.A != 255) { c = Color.FromArgb(255, c); } if (_bolCheckValueExistWhenAdd) { if (IndexOf(c) < 0) { _myItems.Add(c); } } else { _myItems.Add(c); } }
/// <summary> /// get color index /// </summary> /// <param name="c">color</param> /// <returns>index , if not found , return -1</returns> public int IndexOf(Color c) { if (c.A == 0) { return -1; } if (c.A != 255) { c = Color.FromArgb(255, c); } for (var iCount = 0; iCount < _myItems.Count; iCount++) { var color = _myItems[iCount]; if (color.ToArgb() == c.ToArgb()) { return iCount; } } return -1; }
/// <summary> /// delete special color /// </summary> /// <param name="c">color value</param> public void Remove(Color c) { var index = IndexOf(c); if (index >= 0) _myItems.RemoveAt(index); }
/// <summary> /// get color at special index , if index out of range , return default color /// </summary> /// <param name="index">index</param> /// <param name="defaultValue">default value</param> /// <returns>color value</returns> public Color GetColor(int index, Color defaultValue) { index --; if (index >= 0 && index < _myItems.Count) { return _myItems[index]; } return defaultValue; }