stdole.IPicture.Disp to System.Drawing.Ico

cuisancio

Member
Joined
Mar 7, 2006
Messages
11
Programming Experience
Beginner
Hello, I need to put icons in a vb.net menu. The icons are in a AxImageList called Images, so when i have to extract an icon i do Images.ListImages("name").ExtractIcon but this method returns a stdole.IPictureDisp.

The problem is that i have a class to put the icons in the menu which receives as parameter a System.Drawing.Icon not a stole.IPictureDisp.

Please, how can i convert the icon in the stdole.IPictureDisp format in a System.Drawing.Icon????

I tried to use a CType but VB.net says that is a restrictive conversion and when i run the app the icon doesn't appear.
 
i don't use .Net control ImageList because when they gave me the app, the icons were in a AxImageList (i didn't put the icons in a AxImageList, they were in a AxImageList XDDD)

Please, is there some easy way to move the icons in the AxImageList to a .Net ImageList? or , as i said before, some way to convert the stdole.IPictureDisp to system.Drawing.Icon?
 
Thk for the link, i had read another similar so i put a ImageConverter class as this:

Public Class ImageConverter
Inherits System.Windows.Forms.AxHost

Public Sub New(ByVal pGUID As String)
MyBase.New(pGUID)
End Sub

Public Shared Function ImageToIPicDisp(ByVal value As System.Drawing.Image) As stdole.IPictureDisp
Return System.Windows.Forms.AxHost.GetIPictureDispFromPicture(value)
End Function

Public Shared Function IPicDispToImage(ByVal value As stdole.IPictureDisp) As System.Drawing.Image
Return System.Windows.Forms.AxHost.GetPictureFromIPictureDisp(CType(value, Object))
End Function
End Class


And to put icons in the menu i use this method (i write only a fragment of the code) of a class IconMenuItem that inherits MenuItem:

Public Sub New()
MyBase.New()
MyBase.OwnerDraw = True

InitializeComponent()
End Sub

Public Sub New(ByVal TopItem As MenuItem, ByVal Text As String, ByVal Imagen As Image, ByVal Delegate As EventHandler)
MyBase.New(Text, Delegate)
MyBase.OwnerDraw = True
InitializeComponent()
_Text = Text : _Delegate = Delegate
_TopItem = TopItem : _Imagen = Imagen
_TipoIcon = IconType.Imagen
End Sub

Public Overloads Function Add() As IconMenuItem
_TopItem.MenuItems.Add(Me)
Return Me
End Function

So, in theory, if i pass a Image to this, the icon will be set.

In the form, i do:
Dim men As IconMenuItem
Dim help As MenuItem = MainMenu1.MenuItems.Add("Help")


Dim Imag As Image = ImageConverter.IPicDispToImage(Images.ListImages("help").ExtractIcon)
men = New IconMenuItem(Help, "About...", Imag, AddressOf m_Help_About_Click)
men.Add()

But it doesn't work :(

---------------------------------------------------
In the other hand...

I did an example with a ImageList (with some icons i downloaded XD) instead of the AxImageList and it works. But the problem is that those icons are in the AxImageList, i don't have them "phisically", if only there were some easy way to get that icons and put them in a ImageList...

Thnks for your replies!!!!!!
 
Back
Top