【问题标题】:DataGridView ImageColumn Displays PNG Picture withTransparent Background keeping previous Drawing in Picture location Winform VB.NETDataGridView ImageColumn 显示带有透明背景的 PNG 图片,将先前的绘图保留在图片位置 Winform VB.NET
【发布时间】:2016-04-06 15:34:01
【问题描述】:

我在 datagridview 中使用 ImageColumn 来查看保存在 DB 中的 PNG 图片。 每当我更改表单中的选项卡并使用 DGV 返回选项卡时,PNG imgae 透明背景都会保留显示在同一位置的先前控件的绘图。此外,当我尝试更改图像并保存新的 PNG 图像时,DGV 会更新,它会在透明部分显示上一张图片的部分内容。 我将 imageColumn 单元格默认样式选项中的背景颜色和 SelectionBackground 颜色更改为白色,但没有任何更改。任何机构都可以帮我解决这个问题吗? 清关请看图片..

【问题讨论】:

  • 我想我们需要看看相关的代码。也许您也想删除 c# 或 vb.net 标记?

标签: c# vb.net visual-studio-2010 datagridview datagridviewimagecolumn


【解决方案1】:

终于用代码解决了!

使用CellPaining在单元格中绘制一个白色矩形。

Private Sub ItemsList_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles ItemsList.CellPainting
        If ItemsList.Columns(e.ColumnIndex).Name = "iconCol" And e.RowIndex >= 0 Then
            e.Paint(e.CellBounds, DataGridViewPaintParts.All)
            e.Graphics.FillRectangle(Brushes.White, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Width, e.CellBounds.Height)
        End If

不要使用 DrawRectangle 使用 FillRecangle 来绘制矩形,以便用颜色填充背景。

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多