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)

  • 相关阅读:
    二叉树相关题目
    二叉树的遍历
    mysql获取某个表中除了某个字段名外的所有字段名
    设计模式之原型模式
    设计模式之工厂方法模式
    设计模式之代理模式
    设计模式之装饰模式
    设计模式之策略模式
    设计模式之简单工厂模式
    Redis的使用及参考代码
  • 原文地址:https://www.cnblogs.com/zealsoft/p/163678.html
Copyright © 2011-2022 走看看