private void listBox1_DrawItem(object sender, DrawItemEventArgs e) { if (!bInitialized) { return; } e.DrawFocusRectangle(); int index = e.Index; if (index < 0 || index >= data.Color.ColorPallette.Count) { return; } int colorRectWidth = 40; int itemYAdditionalOffset = 4; PalletteColor color = data.Color.ColorPallette[index]; //-- Draw the Color Rectangle Rectangle rect = new Rectangle(); rect.X = e.Bounds.X; rect.Y = e.Bounds.Y; rect.Width = colorRectWidth; rect.Height = e.Bounds.Height - itemYAdditionalOffset; //-- fill the rectangle Brush colorBrush = new SolidBrush(color.Color); e.Graphics.FillRectangle(colorBrush, rect); colorBrush.Dispose(); //-- Draw the border Pen pen = new Pen(Color.Gray, 2); pen.Alignment = PenAlignment.Inset; pen.DashStyle = DashStyle.Solid; pen.LineJoin = LineJoin.Round; e.Graphics.DrawRectangle(pen, rect); pen.Dispose(); Brush brush = Brushes.Black; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { brush = Brushes.White; } //-- Draw the back ground Brush brushBackground = new SolidBrush(e.BackColor); e.Graphics.FillRectangle(brushBackground, e.Bounds.X + 45, e.Bounds.Y, e.Bounds.Width - colorRectWidth, e.Bounds.Height - itemYAdditionalOffset); e.Graphics.DrawString(color.ToString(), e.Font, brush, e.Bounds.X + 45, e.Bounds.Y); }
public void AddMouseOver(string colorName, int shadesBrighter) { Expect.IsTrue(this.colorsByName.ContainsKey(colorName)); PalletteColor color = this.colorsByName[colorName]; string newColorName = colorName + "_mouseover"; if (this.colorsByName.ContainsKey(newColorName)) { this.colorsByName[newColorName] = new PalletteColor(newColorName, this.Brighten(color.HtmlHexColor)); } else { this.colorsByName.Add(newColorName, new PalletteColor(newColorName, this.Brighten(color.HtmlHexColor))); } }
// Add Pallette Color private void button2_Click(object sender, EventArgs e) { if (!bInitialized) { return; } colorDialog1.FullOpen = true; DialogResult result = colorDialog1.ShowDialog(); if (result == DialogResult.OK) { PalletteColor palletteColor = new PalletteColor(); palletteColor.Color = colorDialog1.Color; palletteColor.Weight = 1.0f; data.Color.ColorPallette.Add(palletteColor); refreshPalletteListBox(); } }