【问题标题】:How to make transparent alpha color of a cell datagridview?如何使单元格数据网格视图的透明 alpha 颜色?
【发布时间】:2017-02-19 01:31:04
【问题描述】:

我有一个如下的datagridview:

我想让单元格数据网格视图的背景颜色约为 20%、50%、... 透明(不完全透明),其中背景中有颜色(即黑色、紫色、灰色、... )?

我尝试了很多方法,但我无法做到:

private void CustomerDGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    try
    {
        // Black 20%
        if (e.ColumnIndex == 1)
        {
            SetCellsTransparent(e.RowIndex, Color.Black, 0.2);
        }

        // Purple 50%
        if (e.ColumnIndex == 2)
        {
            SetCellsTransparent(e.RowIndex, Color.Purple, 0.5);
        }

        // Gray 100%
        if (e.ColumnIndex == 3)
        {
            SetCellsTransparent(e.RowIndex, Color.Gray, 1);
        }
    }
    catch (Exception) { }
}

public void SetCellsTransparent(int rowIdx, Color color, double transparency)
{
    //Color color = ColorTranslator.FromHtml("#000000");
    //Color color = Color.Red;
    //this.Rows[rowIdx].Cells[0].Style.BackColor = color;

    //this.Rows[rowIdx].Cells[0].Style.BackColor = Color.FromArgb(50, color);

    var whiteness = 255 - Convert.ToInt32(transparency * 255);
    this.Rows[rowIdx].Cells[0].Style.BackColor = Color.FromArgb(255, whiteness, whiteness); //Red

    this.ClearSelection();
}

任何关于这些的提示都会有很大帮助。提前致谢。

【问题讨论】:

标签: c# datagridview cell background-color transparent


【解决方案1】:

参考下面的链接后,我确实运行良好。 http://www.codeproject.com/Articles/6502/Transparency-Tutorial-with-C-Part

我希望这对需要的人有用!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    相关资源
    最近更新 更多