zoukankan      html  css  js  c++  java
  • VS2005对ActiveX的图象属性的处理

    在VS2003中,如果要给ActiveX控件的图象属性赋值,需要调用VB6.ImageToPicture。因为VS2003把图象属性的类型处理为stdole.IPictureDisp对象,所以需要利用这个函数将System.Drawing.Image转换为stdole.IPictureDisp。如:

            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))

    如果在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)

  • 相关阅读:
    hive 数据hadoop数据etl交换
    团队冲刺(三)
    团队冲刺(二)
    CVPR2019论文热词云的实现
    团队冲刺(一)
    团队开发之电梯演讲----团队项目介绍--“益青春APP”
    android的finish()方法
    java web项目通过外网ip访问
    MySQL出现错误1205-Lock wait timeout exceeded; try restarting transaction
    团队开发(自己的理解)
  • 原文地址:https://www.cnblogs.com/zealsoft/p/163678.html
Copyright © 2011-2022 走看看