[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

exposing an imagelist property in my custom control

hello experts... i'm trying to expose a propery to attach an imagelist to my custom control... but i dont see the property... and i was thinking maybe somehow i have to do the "custom" property like a listview control uses to attach the imagelist.  can someone explain how i can attach an imagelist to my control?

or better yet, if you can tell me how i can create an instance of an imagelist without having to include comctl32.ocx in my custom control project.  comctl32 will be included in the project that i plan to use the custom control in...

i'm trying this to expose the imagelist property...
'=======================================
dim m_ImageList as object
Public Property Get ImageList() As Object
   ImageList = m_ImageList
End Property
Public Property Let ImageList(ByVal NewImageList As Object)
   Set m_ImageList = NewImageList
End Property
Public Property Set ImageList(ByVal NewImageList As Object)
   Set m_ImageList = NewImageList
End Property
'=======================================
0
RobK6364
Asked:
RobK6364
  • 2
1 Solution
 
danaseamanCommented:
If using VbAccelerator ImageList then you only need to supply the handle (m_hIml) which is a long. If you are using the Vb Imagelist then you need to pass an object. Here is code that can handle both situations using Varaint.

Public Property Let ImageList(Value As Variant)
Dim hIml As Long
   '
    If (VarType(Value) = vbLong) Then
      ' Assume a handle to an image list:
      hIml = Value
   ElseIf (VarType(hIml) = vbObject) Then
      ' Assume a VB image list:
      On Error Resume Next
      ' Get the image list initialised.
      Value.ListImages(1).Draw 0, 0, 0, 1
      hIml = Value.hImageList
      If (Err.Number = 0) Then
          ' OK
      Else
          gErr 4, "UniTreeViewCtl"
      End If
      On Error GoTo 0
   End If
   
   If Not (hIml = 0) Then
      SendMessageL m_hWnd, TVM_SETIMAGELIST, TVSIL_NORMAL, hIml
   End If
   '
End Property
0
 
danaseamanCommented:
By the way...If you want to create the Imagelist in your control there is code at VbAccelerator to do this. The dependency is ComCtl32.Dll which is present in all Windows OS and does not need to be included in your deployment package. There is a great example on how to implement this at PSC. You initialise the ImageList using "InitializeImageListSmall" and supply a bitmap strip using "ImageListSmall_AddBitmap". Link http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=56021&lngWId=1. Also see VbAccelerator.com for lighweight ImageList classes.
0
 
RobK6364Author Commented:
thanks, got it workin : )
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now