在 vb.net 中的 datagridviewimagecolumn 中显示图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16564978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:53:58  来源:igfitidea点击:

displaying image in datagridviewimagecolumn in vb.net

vb.net

提问by joshua

i have a datagridviewimagecolumn which I added using the small arrow when you click the datagridview or should I say not programmatically added.

我有一个 datagridviewimagecolumn,当​​您单击 datagridview 或我应该说不是以编程方式添加时,我使用小箭头添加了它。

Can anyone tell me how to display image in datagridviewimagecolumn when the form loads?

谁能告诉我如何在加载表单时在 datagridviewimagecolumn 中显示图像?

回答by Alex

Programmatically Add Image

以编程方式添加图像

This will add YourImage.pngto the firstrow (Rows(0)) in DataGridView1

这将添加YourImage.png第一行 ( Rows(0))DataGridView1

    Dim ColImage As New DataGridViewImageColumn
    Dim Img As New DataGridViewImageCell

    'Set Name
    ColImage.Name = "ColImg"

    'Set Header text
    ColImage.HeaderText = "Your Image!"

    'Add column to datagridview
    DataGridView1.Columns.Add(ColImage)

    'Set image value
    Img.Value = Image.FromFile("C:\YourImage.png")

    'Add the image cell to a row
    DataGridView1.Rows(0).Cells.Add(Img)

Adding Image By DataGridView Interface

通过 DataGridView 接口添加图像

Click on the small arrow in the upper right hand corner of your datagridview. Click "Edit Columns"

单击数据网格视图右上角的小箭头。点击“编辑列

Edit columns

编辑列

  1. A new window pops up, now click on "Add" to add a new column.
  2. Another window appears, select "DataGridViewImageColumn" as the type in the dropdown menu.
  3. Set the nameand header text, then click on Add
  1. 弹出一个新窗口,现在点击“添加”添加一个新列。
  2. 出现另一个窗口,在下拉菜单中选择“ DataGridViewImageColumn”作为类型。
  3. 设置名称标题文本,然后单击添加

Add column

添加列

All you need to do next is select the image.

您接下来需要做的就是选择图像。

Image properties

图像属性

*Tip: Set your ImageLayout to "Zoom" and you'll get a clear image.

*提示:将您的 ImageLayout 设置为“缩放”,您将获得清晰的图像。

回答by Tom F

You can just set the DataGridViewImageColumn.Imageproperty. More information here.

您可以只设置DataGridViewImageColumn.Image属性。更多信息在这里。