Dim bmp1 As New Bitmap(strm1)
Dim strm2 As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream("PROP.CONSTRUC.bmp")
ChkList1.set_ItemImage(ChkList1.NewIndex, VB6.ImageToPicture(bmp1))
Dim strm2 As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream("PROP.CONSTRUC.bmp")
ChkList1.set_ItemImage(ChkList1.NewIndex, VB6.ImageToPicture(bmp1))
如果在VS2005 Beta 2下运行上面的代码会导致一个System.InvalidCastException异常。提示信息为:
Unable to cast COM object of type 'System.Drawing.Image' to class type ''. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
不过这段信息并不能说明错误的真实原因。实际上这个异常是因为VS2005将ActiveX控件图象属性的类型处理为System.Drawing.Image,也就是说不再需要VB6.ImageToPicture的转换了。你可以将代码这样写:
Dim bmp1 As New Bitmap(strm1)
Dim strm2 As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream("PROP.CONSTRUC.bmp")
ChkList1.set_ItemImage(ChkList1.NewIndex, bmp1)
Dim strm2 As System.IO.Stream = Me.GetType.Assembly.GetManifestResourceStream("PROP.CONSTRUC.bmp")
ChkList1.set_ItemImage(ChkList1.NewIndex, bmp1)