CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2009
    Posts
    6

    Question Adding multiple images to a property of an usercontrol

    Hi.
    If anyone could help me, I would aprecciate that.
    I have an imagelist control in a usercontrol I made.
    I would like to create a property for this usercontrol, to select multiple images (in an 'openfiledialog'), and adding them to the imagelist inside the usercontrol.
    So, what's the type of this property?

    Public Property thelistofimages as [¿?]

    It should be an array of images I guess. And then in the 'set' of the property it would add all the images to the imagelist. Is that posible?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Adding multiple images to a property of an usercontrol

    Something like this?

    Code:
    Public Property thelistofimages as (List of(), MyImageList)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Oct 2009
    Posts
    6

    Re: Adding multiple images to a property of an usercontrol ( Vb .net 2.0.5)

    Sorry, didn't get that. I'm a newbie in this stuff :P.

    I can't get the code...
    Code:
    Public Property thelistofimages as (List of(), MyImageList)
    ...to work. I tried some variations, but nothing. Wrong type, too many parameters, etc.

    But if I use
    Code:
    Public Property thelistofimages As List(of image)
    In the properties panel of the usercontrol, it opens the Image Collection Editor dialog.
    That's working fine, BUT, when I press add image, it says:
    'Cannot create an instance of System.Drawing.Image because it is an abstract class', etc...

    Any suggestions?
    Thanks for the tip, I think i'm getting closer.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Adding multiple images to a property of an usercontrol

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Oct 2009
    Posts
    6

    Re: Adding multiple images to a property of an usercontrol

    Thanks for the answer, but I guess that's not what I need right now.

    What I need is to do this:
    1) Place an Usercontrol in the Mainform
    2) When you click on the Usercontrol, in the PropertiesPanel, it shows a property (for example: 'Filepaths')
    3) When you click the 'Filepaths' property, it shows an OpenFileDialog, so that you can select multiple files.
    4) This list of FilePaths, will be the value of the 'Set' of the property 'Filepaths'
    5) Then, inside the 'Set' I can divide this paths, to do whatever I like (for example: adding the files to an ImageList).

    Code:
    Public Partial Class UserControl1
    	Inherits System.Windows.Forms.UserControl
    	
    	Public Sub New()
    		Me.InitializeComponent()
    
    	End Sub
    	Public Property filepaths As List(Of [i-have-no-idea])
    		Set(Value as List(Of [i-have-no-idea]))
    			For i = 0 To value.Count
    				imagelist1.Images.Add(value.Item(i))
    			Next
    		End Set
    		Get
    		End Get
    	End Property
    End Class
    I know this code doesn't work, its only an example :P.

    Any ideas?
    I did a property that lets you select an image from your pc and opens it in a picturebox inside the usercontrol, and I did a property that let you select multiple images with the images collection editor, but I can't get both to work :S.

  6. #6
    Join Date
    Oct 2009
    Posts
    6

    Re: Adding multiple images to a property of an usercontrol

    I know there's got to be a way to do this :P... but I just can't get it hehehehe.

    with the code...
    Code:
        Private _imglst as ImageList.ImageCollection
        Public Property imglst as ImageList.ImageCollection
        	Set (value as ImageList.ImageCollection)
        		'msgbox(value.Count)
        	End Set
       	Get
        		
        	End Get
        end property
    ...in the properties of the usercontrol, I have the property 'imglst' wich opens an Images Collection Editor, that lets you add images, modify their parameters, see a thumbnail, etc.
    The problem is that the "msgbox(value.Count)" line gives this error:

    System.InvalidOperationException:
    Error:Object reference not set to an instance of an object. --->

    I guess its because there is no imagelist and I'm using an imagecollection :P. But this imagecollection type is the only type that shows this Images Collection Editor (that lets you add multiple images and modify their parameters)...
    Any Ideas? How can I create an instance in here?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured