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)

  • 相关阅读:
    2015总结篇
    Android应用性能优化实践
    Android国外学习资源汇总
    直接拿来用!十大Material Design开源项目
    selenium12-读取文件 excel
    selenium11-自动化练习读取文件txt
    selenium10-python3部分代码复习
    selenium09-自动化练习案例
    selenium08-测试用例模块化与数据分离
    selenium07-处理 alter 对话框
  • 原文地址:https://www.cnblogs.com/zealsoft/p/163678.html
Copyright © 2011-2022 走看看