在 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
displaying image in datagridviewimagecolumn in 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.png
to 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"
单击数据网格视图右上角的小箭头。点击“编辑列”
- A new window pops up, now click on "Add" to add a new column.
- Another window appears, select "DataGridViewImageColumn" as the type in the dropdown menu.
- Set the nameand header text, then click on Add
- 弹出一个新窗口,现在点击“添加”添加一个新列。
- 出现另一个窗口,在下拉菜单中选择“ DataGridViewImageColumn”作为类型。
- 设置名称和标题文本,然后单击添加
All you need to do next is select the image.
您接下来需要做的就是选择图像。
*Tip: Set your ImageLayout to "Zoom" and you'll get a clear image.
*提示:将您的 ImageLayout 设置为“缩放”,您将获得清晰的图像。