Link to home
Start Free TrialLog in
Avatar of S-L-D-
S-L-D-

asked on

usercontrol question.

I have a usercontrol that i developed.

This control have 20 imagebox

how do I do to control which picture will be showed in which imagebox (from the form that have the control)


explaining better, what i need is this:

I need a "property" of the usercontrol that allow me to change the pictures in everyone of the 20 images that it contains...

Is it hard??? can anybody help plz???

Thank You
Avatar of sgayatri
sgayatri

For this you should create a property of your usercontrol and write code to change the pictures in everyone of these 20 controls
Can you just post the code in your user control.....
I suggest using a couple of methods:

Public Sub setPicture(Pic As Object, Idx As Integer)
...
End Sub

Public Function getPicture(Idx As Integer) As Object
...
End Function
You can also put two properties in your usercontrol:

Private m_objPicture As StdPicture
Private m_lPicIndex As Long

...

Public Property Get Picture() As StdPicture
    Set Picture = m_objPicture
End Property

Public Property Set Picture(objPicture As StdPicture)
    Set m_objPicture = objPicture
End Property

Public Property Get PicIndex() As Long
    PicIndex = m_lPicIndex
End Property

Public Property Let PicIndex(ByVal lPicIndex As Long)
    m_lPicIndex = lPicIndex
End Property
When you read/write the picture property you can use the PicIndex property to choose the right ImageBox
Avatar of S-L-D-

ASKER

well... i forgot something... the pictures that i want to put in the 20 image box is in a imagelist on the main project

only a idea:
could i put the index and the picture in one function only, like this:

public function GetImage (index as integer,picture as (dunno)

end function

thank you very much

hi,
  try this. its from one of my user controls. Mail me if u find any trouble


----------control prop var-------

Private m_SkinDown As Picture
 
--------------------------------



Public Property Get SkinDown() As Picture
    Set SkinDown = m_SkinDown
End Property



Public Property Set SkinDown(ByVal NewValue As Picture)
    Set m_SkinDown = NewValue
   
    //set the picture here
   
    PropertyChanged "SkinDown"
End Property




----------UserControl functions--------------------------

Private Sub UserControl_InitProperties()
    'Initialize Properties for User Control
       
    Set SkinDown = LoadPicture("")

    // also include other stuff
End Sub





Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    // other stuff

    Set SkinDown = PropBag.ReadProperty("SkinDown", Nothing)
End Sub





If you use a imagelist control you can pass it's name as a property and then use it to set the images

like this:

Option Explicit
Const m_def_ilName = ""
Dim m_ilName As String

Public Property Get ilName() As String
    ilName = m_ilName
End Property

Public Property Let ilName(ByVal New_ilName As String)
    m_ilName = New_ilName
    PropertyChanged "ilName"
    setImages
End Property

Private Sub UserControl_InitProperties()
    m_ilName = m_def_ilName
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    m_ilName = PropBag.ReadProperty("ilName", m_def_ilName)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    Call PropBag.WriteProperty("ilName", m_ilName, m_def_ilName)
End Sub

Private Sub setImages()

    Dim iList As ListImage
    Dim Ctl As Object
   
    If m_ilName <> "" Then
        For Each Ctl In ParentControls
            If Ctl.Name = m_ilName Then
                Set iList = Ctl
                Exit For
            End If
        Next
        If Not iList Is Nothing Then
            ' you can set your images here
        End If
    End If

End Sub
Sorry ...

Dim iList As ImageList
ASKER CERTIFIED SOLUTION
Avatar of mmusante
mmusante

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial