private void button3_Click(object sender, EventArgs e) { colorDialog1 = new ColorDialog() { ShowHelp = true, Color = textBox1.ForeColor }; if (colorDialog1.ShowDialog() == DialogResult.OK) { _splashColourCode = colorDialog1.ToString(); } }
//----------------------------------------------------------------------------------------- private void colorTextBox_TextChanged(object sender, EventArgs e) { color = new ColorDialog(); color.AllowFullOpen = true; color.ShowHelp = true; color.Color = colorTextBox.ForeColor; if (color.ShowDialog() == DialogResult.OK) { colorTextBox.Text = color.ToString(); color.AllowFullOpen = false; color.ShowHelp = false; return; } chatTextBox.ForeColor = color.Color; }
public void ColorDialogTest() { cd = new ColorDialog(); Assert.AreEqual(Color.Black, cd.Color, "#1"); Assert.IsTrue(cd.AllowFullOpen, "#2"); Assert.IsFalse(cd.AnyColor, "#3"); Assert.IsFalse(cd.FullOpen, "#4"); Assert.IsNotNull(cd.CustomColors, "#5"); Assert.IsFalse(cd.ShowHelp, "#6"); Assert.IsFalse(cd.SolidColorOnly, "#7"); Assert.AreEqual("System.Windows.Forms.ColorDialog, Color: Color [Black]", cd.ToString(), "#8"); cd.Color = Color.Red; Assert.AreEqual(Color.Red, cd.Color, "#9"); cd.AllowFullOpen = false; cd.FullOpen = true; Assert.IsTrue(cd.FullOpen, "#10"); int[] custom_colors = new int[] { Color.Yellow.ToArgb(), Color.Red.ToArgb() }; cd.CustomColors = custom_colors; Assert.IsNotNull(cd.CustomColors, "#10a"); Assert.AreEqual(16, cd.CustomColors.Length, "#10aa"); Assert.AreEqual(Color.Red.ToArgb(), cd.CustomColors[1], "#10ab"); Assert.AreEqual(Color.FromArgb(0, 255, 255, 255).ToArgb(), cd.CustomColors[15], "#10ac"); cd.CustomColors = null; Assert.IsNotNull(cd.CustomColors, "#10b"); Assert.AreEqual(16, cd.CustomColors.Length, "#10bb"); Assert.AreEqual(Color.FromArgb(0, 255, 255, 255).ToArgb(), cd.CustomColors[0], "#10bc"); cd.AllowFullOpen = true; cd.CustomColors = custom_colors; Assert.IsNotNull(cd.CustomColors, "#10c"); Assert.AreEqual(16, cd.CustomColors.Length, "#10cc"); }