2013-06-19 66 views
3

我需要在vb.net中動態創建圖像控件。在聲明new image(dim img as New Image()它顯示以下錯誤:vb.net中的動態圖像控制

Error: New cannot be used in a class that is MustInherit

有沒有解決方案?這是我需要使用它:

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) 

回答

2

看來,你所得到的System.Drawing命名空間中的類Image,因爲這是一個抽象類。如果包含System.Drawing名稱空間,則必須指定要使用的類的位置。

例如:

Dim imgBox As New System.Windows.Controls.Image() 
+1

感謝Guffa它曾與昏暗imgBox作爲新WebControls.Image() – Suchith