3

我需要在 vb.net 中动态创建一个图像控件。在声明new image(dim img as New Image()它时显示以下错误:

错误:不能在 MustInherit 类中使用 New

有什么解决办法吗?这是我需要使用它的地方:

Dim imgBox As New Image()
imgBox.ImageUrl = "~/Images/" & strImgName
Dim tr As New TableRow
Dim tdRight As New TableCell
Dim tdLeft As New TableCell
tdRight.Controls.Add(imgBox)
tdLeft.Controls.Add(imgBox)
tr.Controls.Add(tdLeft)   'adding left cell
tr.Controls.Add(tdRight)  'adding right cell
tb.Controls.Add(tr) 
4

1 回答 1

2

似乎您正在命名空间中获取Image该类System.Drawing,因为该类是抽象的。如果您已包含System.Drawing命名空间,则必须指定Image要使用的类的位置。

例如:

Dim imgBox As New System.Windows.Controls.Image()
于 2013-06-19T07:50:29.450 回答