如何从visual studio中的颜色对话框中获取十六进制颜色代码?

时间:2016-07-04 12:48:13

标签: c# visual-studio-2015 color-picker

我在visual studio中有一个颜色对话框,我目前正在使用这个c#代码显示颜色对话框并将颜色设置为面板:

private void ColorButton_Click(object sender, EventArgs e)
{
    if (colorDialog1.ShowDialog() == DialogResult.OK)
    {
        ColorPanel.BackColor = colorDialog1.Color;
    }
}

如何将标签设置为颜色选择器的十六进制颜色代码?

1 个答案:

答案 0 :(得分:11)

你可以试试这个

  1. 获取颜色的var propCount = 0; $.each(data.thumbnails, function(index, thumbnails) { propCount++; if(propCount == 1) { $('#ThumbnailHolder').append('<img src="http://images.sportsdirect.com/images/products/' + thumbnails + '" class="LittleThumbs" BigImageLink="http://images.sportsdirect.com/images/products/' + thumbnails + '">'); } else { $('#ThumbnailHolder').append('<a rel="example_group" title="<?PHP echo $name;?>" class="FancyBox FancyThumbs" href="http://images.sportsdirect.com/images/products/' + thumbnails + '"><img src="http://images.sportsdirect.com/images/products/' + thumbnails + '" class="LittleThumbs" BigImageLink="http://images.sportsdirect.com/images/products/' + thumbnails + '"></a>'); } }); (Alpha,红色,绿色,蓝色)表示
  2. 过滤掉 Alpha 频道:ARGB
  3. 将值格式化为十六进制(& 0x00FFFFFF
  4. 实施

    "X6"

    修改:如果您想从 String code = (colorDialog1.Color.ToArgb() & 0x00FFFFFF).ToString("X6"); 获取Color 返回,请尝试code

    FromArgb