Csharp: Winform 顏色選擇器 Color convert RGB and RGB convert Color

 /// <summary>
        /// 選擇顏色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            //是否選擇了顏色
            if (colorDialog1.ShowDialog(this) == DialogResult.OK)
            {
                //System.Drawing.Color.FromArgb
                this.textBox2.Text = ColorTranslator.ToHtml(colorDialog1.Color);
                this.textBoxA.Text = colorDialog1.Color.A.ToString();
                this.textBoxB.Text = colorDialog1.Color.B.ToString();
                this.textBoxG.Text = colorDialog1.Color.G.ToString();
                this.textBoxR.Text = colorDialog1.Color.R.ToString();
                this.textBoxArgb.Text = colorDialog1.Color.ToArgb().ToString();


                //1
                //this.button1.BackColor = ColorTranslator.FromHtml(this.textBox2.Text.Trim());
                //2
                //this.button1.BackColor =Color.FromArgb(int.Parse(this.textBoxArgb.Text.Trim()));
                //3
                this.button1.BackColor = Color.FromArgb(int.Parse(this.textBoxR.Text.Trim()), int.Parse(this.textBoxG.Text.Trim()), int.Parse(this.textBoxB.Text.Trim()));
                

            }
        }
        /// <summary>
        /// 選擇字體
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog(this) == DialogResult.OK)
            {
                this.textBox1.Text = fontDialog1.Font.ToString();
            }
        }

你可能感兴趣的:(color,csharp)