-1-
-2-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace wfa0031
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void writecolor()
{
label3.Text = pictureBox1.BackColor.Name.ToString();
label4.Text = pictureBox1.BackColor.A.ToString() + ":" +
pictureBox1.BackColor.R.ToString() + ":" +
pictureBox1.BackColor.G.ToString() + ":" +
pictureBox1.BackColor.B.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
ColorDialog MyDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = true;
// Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = true;
// Sets the initial color select to the current text color.
MyDialog.Color = textBox1.ForeColor;
// Update the text box color if the user clicks OK
if (MyDialog.ShowDialog() == DialogResult.OK)
textBox1.ForeColor = MyDialog.Color;
}
private void button2_Click(object sender, EventArgs e)
{
ColorDialog MyDialog = new ColorDialog();
// Keeps the user from selecting a custom color.
MyDialog.AllowFullOpen = false;
// Allows the user to get help. (The default is false.)
MyDialog.ShowHelp = true;
// Sets the initial color select to the current text color.
MyDialog.Color = textBox1.BackColor;
// Update the text box color if the user clicks OK
if (MyDialog.ShowDialog() == DialogResult.OK)
textBox1.BackColor = MyDialog.Color;
}
private void button3_Click(object sender, EventArgs e)
{
ColorDialog MyDialog = new ColorDialog();
MyDialog.AnyColor = false;
MyDialog.SolidColorOnly = true;
//MyDialog.Color = Color.Red;
// Update the text box color if the user clicks OK
if (MyDialog.ShowDialog() == DialogResult.OK)
textBox1.BackColor = MyDialog.Color;
// Show current color.
string strARGB = MyDialog.Color.ToString();
MessageBox.Show(strARGB, "Color is:");
string strARGB1 = MyDialog.Color.Name.ToString();
MessageBox.Show(strARGB1, "Color is:");
}
private void button4_Click(object sender, EventArgs e)
{
//ColorDialog With Custom Color
ColorDialog dlg = new ColorDialog();
dlg.FullOpen = true;
// Define the first five of the custom color settings
// 0xAARRGGBB where AA is alpha,
// RR is red,
// GG is green
// BB is blue
// expressed as the hexadecimal byte equivalent
dlg.CustomColors = new int[5]{0x00ff8040, 0x00c256fe,
0x00aa2005, 0x0004f002, 0x002194b5};
dlg.ShowDialog();
}
private void button5_Click(object sender, EventArgs e)
{
DialogResult dr= colorDialog1.ShowDialog();
if (dr==DialogResult.OK)
{
pictureBox1.BackColor = colorDialog1.Color;
writecolor();
}
}
private void Form1_Load(object sender, EventArgs e)
{
writecolor();
}
}
}
-3-
-4-