Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > vb.net:imagelist loses images when the image size property is changed

Reply
Thread Tools

vb.net:imagelist loses images when the image size property is changed

 
 
Peter Ho
Guest
Posts: n/a
 
      07-25-2003
Hello,

does anyone know why my imagelist loses its entire imagecollection when I
change the imagesize property of the imagelist during run-time? This does
not happen when I change the imagesize property during design time. Does
anyone know a way to work around this problem?

kind regards,

Peter


 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      07-25-2003
How are you changing it? Can you post some sample code which repros the problem?

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


"Peter Ho" <(E-Mail Removed)> wrote in message news:bfrhmi$k7d$(E-Mail Removed)...
> Hello,
>
> does anyone know why my imagelist loses its entire imagecollection when I
> change the imagesize property of the imagelist during run-time? This does
> not happen when I change the imagesize property during design time. Does
> anyone know a way to work around this problem?
>
> kind regards,
>
> Peter
>
>



 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      07-26-2003
Peter,
It appears that if you set the ImageList's ImageSize property and Images collection
at design time, you won't be able to change the ImageSize without recreating the
Images collection as well.

I recommed you create a resource file, then add your images to that resource file,
then read the images from the resource (which gets embedded in your assembly)
at runtime.

Here is are great article on how to do this:
http://www.jelovic.com/articles/reso...ual_studio.htm
- Note, once you add the images to the resource file (using Resourcer tool)
make sure to *rename* them since the default name includes the path.

Here is the VB.NET code that I used to resize the ImageList and add
two images at runtime.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.ImageList1.ImageSize = New Size(16, 16) ' This will reset the Images collection

' Create a resource manager to retrieve images embedded in the assembly
Dim resManager As New System.Resources.ResourceManager("ImageList.Form1" , _
System.Reflection.Assembly.GetExecutingAssembly())

' Add image1 to ImageList's Images collection
Dim myImage As Bitmap = CType(resManager.GetObject("Image1.jpg"), Bitmap)
Me.ImageList1.Images.Add(myImage)

' Add image2 to ImageList's Images collection
myImage = CType(resManager.GetObject("Image2.jpg"), Bitmap)
Me.ImageList1.Images.Add(myImage)
End Sub

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


"Peter Ho" <(E-Mail Removed)> wrote in message news:bfuc2n$d0u$(E-Mail Removed)...
> here is some code that shows my problem, fill the imagelist with some images
> during design time and then runt the code
>
> ************************************************** **************************
> **************************
> ************************************************** **************************
> **************************
> Public Class Form1
>
> Inherits System.Windows.Forms.Form
>
> #Region " Windows Form Designer generated code "
>
> Public Sub New()
>
> MyBase.New()
>
> 'This call is required by the Windows Form Designer.
>
> InitializeComponent()
>
> 'Add any initialization after the InitializeComponent() call
>
> End Sub
>
> 'Form overrides dispose to clean up the component list.
>
> Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>
> If disposing Then
>
> If Not (components Is Nothing) Then
>
> components.Dispose()
>
> End If
>
> End If
>
> MyBase.Dispose(disposing)
>
> End Sub
>
> 'Required by the Windows Form Designer
>
> Private components As System.ComponentModel.IContainer
>
> 'NOTE: The following procedure is required by the Windows Form Designer
>
> 'It can be modified using the Windows Form Designer.
>
> 'Do not modify it using the code editor.
>
> Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
>
> Friend WithEvents Button5 As System.Windows.Forms.Button
>
> Friend WithEvents Button1 As System.Windows.Forms.Button
>
> <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
>
> Me.components = New System.ComponentModel.Container
>
> Dim resources As System.Resources.ResourceManager = New
> System.Resources.ResourceManager(GetType(Form1))
>
> Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
>
> Me.Button5 = New System.Windows.Forms.Button
>
> Me.Button1 = New System.Windows.Forms.Button
>
> Me.SuspendLayout()
>
> '
>
> 'ImageList1
>
> '
>
> Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
>
> Me.ImageList1.ImageStream =
> CType(resources.GetObject("ImageList1.ImageStream" ),
> System.Windows.Forms.ImageListStreamer)
>
> Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
>
> '
>
> 'Button5
>
> '
>
> Me.Button5.Location = New System.Drawing.Point(16, 16)
>
> Me.Button5.Name = "Button5"
>
> Me.Button5.Size = New System.Drawing.Size(192, 8
>
> Me.Button5.TabIndex = 6
>
> Me.Button5.Text = "Count images in imagelist1"
>
> '
>
> 'Button1
>
> '
>
> Me.Button1.Location = New System.Drawing.Point(16, 120)
>
> Me.Button1.Name = "Button1"
>
> Me.Button1.Size = New System.Drawing.Size(240, 72)
>
> Me.Button1.TabIndex = 7
>
> Me.Button1.Text = "Imagelist1.imagesize=new size(20,20)"
>
> '
>
> 'Form1
>
> '
>
> Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
>
> Me.ClientSize = New System.Drawing.Size(304, 251)
>
> Me.Controls.Add(Me.Button1)
>
> Me.Controls.Add(Me.Button5)
>
> Me.Name = "Form1"
>
> Me.Text = "Form1"
>
> Me.ResumeLayout(False)
>
> End Sub
>
> #End Region
>
>
>
> Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button5.Click
>
> MsgBox(CStr(Me.ImageList1.Images.Count))
>
> End Sub
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
> Me.ImageList1.ImageSize = New Size(20, 20)
>
> End Sub
>
> End Class
>
> ************************************************** **************************
> ***************
> ************************************************** **************************
> ***************
>
>
> "Carl Prothman [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > How are you changing it? Can you post some sample code which repros the

> problem?
> >
> > --
> >
> > Thanks,
> > Carl Prothman
> > Microsoft ASP.NET MVP
> > http://www.able-consulting.com
> >
> >
> > "Peter Ho" <(E-Mail Removed)> wrote in message

> news:bfrhmi$k7d$(E-Mail Removed)...
> > > Hello,
> > >
> > > does anyone know why my imagelist loses its entire imagecollection when

> I
> > > change the imagesize property of the imagelist during run-time? This

> does
> > > not happen when I change the imagesize property during design time. Does
> > > anyone know a way to work around this problem?
> > >
> > > kind regards,
> > >
> > > Peter
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
changed state to up changed state to down FastEthernet LINEPROTO-5-UPDOWN surrealarmada@gmail.com Cisco 3 03-07-2007 06:06 PM
how to change images based on action.Even clicking changed images should do respective actions? vj Javascript 3 01-12-2007 12:26 PM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
xmlDocument.Save "&#10;" getting changed changed to "&amp;#10" st@jpa.co.jp ASP .Net 1 10-11-2005 01:30 PM
Bigger image size and lower quality vs. Smaller image size and higher quality Desmond Digital Photography 5 09-27-2003 04:08 AM



Advertisments