質問者
ImageListのImageが表示されない

質問
-
#VS2005T/S,VB,WinXP
2003のResEditor.exeで作成したアイコン集.Resourcesファイルがあり
それを提供するシングルトンクラスを作成してみました。
その中でImageListを構築して提供していますが、
Countは正しくIndexエラーにもなっていませんが、イメージが表示されません。
新規プロジェクトで試したらちゃんと表示されました。
またImageListから要素を取り出して返すGetImageメソッドは
メニューやツールバーに正常に表示されます。原因がわからないところと、
初めて作ってみたシングルトンの何か頓珍漢なところがあればそれについて
ご教授お願いします。
[使用側]
Private _ImgLib As ImageLibrary = ImageLibrary.GetInstance
With TreeView1
.ImageList = _ImgLib.GetImageList
End With
With ListView1
.SmallImageList = _ImgLib.GetImageList
End With
Imports System.Drawing
Imports System.Windows.Forms
Public Class ImageLibrary
Friend Const MyIconResourceName As String = "MyIcons"Private Shared _MyInstance As ImageLibrary
Private _MyAssembly As System.Reflection.Assembly
Private _MyResourceManager As System.Resources.ResourceManager
Private _MyImageList As ImageListPublic Shared Function GetInstance() As ImageLibrary
If _MyInstance Is Nothing Then
_MyInstance = New ImageLibrary
_MyInstance._MyAssembly = _MyInstance.GetType.Assembly
_MyInstance._MyResourceManager = New System.Resources.ResourceManager(MyIconResourceName, _MyInstance._MyAssembly)
_MyInstance._MyImageList = New ImageList
_MyInstance.MakeMyImageList()
End If
Return _MyInstance
End FunctionPublic Function GetIcon(ByVal IconName As IconNames) As Icon
Dim ResourceName As String
Try
ResourceName = [Enum].GetName(GetType(IconNames), IconName)
Return CType(_MyResourceManager.GetObject(ResourceName), System.Drawing.Icon)
Catch ex As Exception
Return Nothing
End TryEnd Function
Public Function GetImage(ByVal IconName As IconNames) As Image
'これはOK
Try
Return _MyImageList.Images(IconName)
Catch ex As Exception
Return Nothing
End TryEnd Function
Public Function GetImageList() As ImageList
'これを使ったイメージが表示されない(真っ白)
Return _MyImageList
End FunctionPrivate Sub MakeMyImageList()
Dim IconValue As IconNames
For Each IconValue In [Enum].GetValues(GetType(IconNames))
Try
_MyImageList.Images.Add(_MyInstance.GetIcon(IconValue))
Catch ex As Exception
'Error Message
End Try
Next
End SubPrivate Sub New()
End SubEnd Class
Public Enum IconNames As Integer
Critical = 0
Exclamation = 1
Information = 2
End Enum