c# 颜色字符串转换为颜色

 



 

private string sColor;
private Color mColor;
private Color mNewColor;
private void panel1_Click(object sender, EventArgs e)
{
DialogResult dr = colorDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
mColor = colorDialog1.Color;

sColor = "#" + mColor.R.ToString("x2") + mColor.G.ToString("x2") + mColor.B.ToString("x2");
sColor = "#" + mColor.A.ToString("x2") + mColor.R.ToString("x2") + mColor.G.ToString("x2") + mColor.B.ToString("x2");

mNewColor = System.Drawing.ColorTranslator.FromHtml(sColor);

label1.BackColor = mNewColor;
panel1.BackColor = mNewColor;

}

}

posted @ 2016-09-11 10:42  mycls  阅读(6352)  评论(0编辑  收藏  举报