• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

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
0
S-L-D-
Asked:
S-L-D-
1 Solution
 
sgayatriCommented:
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.....
0
 
mmusanteCommented:
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
0
 
mmusanteCommented:
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mmusanteCommented:
When you read/write the picture property you can use the PicIndex property to choose the right ImageBox
0
 
S-L-D-Author Commented:
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
0
 
atheekurrahmanCommented:

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





0
 
mmusanteCommented:
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
0
 
mmusanteCommented:
Sorry ...

Dim iList As ImageList
0
 
mmusanteCommented:
Here the full setImages sub ...

Private Sub setImages()

    Dim iList As ImageList
    Dim Ctl As Object
    Dim J As Integer
   
    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
            For J = 0 To iList.ListImages.Count - 1
                If J <= imG.UBound - imG.LBound Then
                    Set imG(imG.LBound + J).Picture = iList.ListImages(J + 1).Picture
                Else
                    Exit For
                End If
            Next
        End If
    End If

End Sub
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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