471,319 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Icon corruption when loading from a resource

When I display icons in controls from an imagelist, the icons are
"corrupted" if they are added from a resource (or a file) but are fine if I
add them using the designer at design time. I need to add the icons
dynamically at runtime.

How can you add the icons at runtime without corrupting the image?
Jul 21 '05 #1
4 1896
How are you adding them?
In what way are they corrupted?

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
When I display icons in controls from an imagelist, the icons are
"corrupted" if they are added from a resource (or a file) but are fine if
I
add them using the designer at design time. I need to add the icons
dynamically at runtime.

How can you add the icons at runtime without corrupting the image?

Jul 21 '05 #2
Here's some code from my test project. I have an icon "help2.ico" that
contains all possible image sizes and formats. At design time, I add it to
ImageList1. I also create ListView1 with 3 items in it, and add the icon to
the project as an embedded resource.

When you run the project, the last two items have corrupted icons. It looks
like the icons are being resized from a larger icon size. How do I tell it
to use the correct icon size from the icon?

Code follows:
--------------

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Set image list
ListView1.SmallImageList = ImageList1

'Set item 0 image
ListView1.Items(0).ImageIndex = 0

'Load from resource
ImageList1.Images.Add(New
System.Drawing.Icon(System.Reflection.Assembly.Get ExecutingAssembly.GetManif
estResourceStream(Me.GetType, "help2.ico")))

'Set item 1 image
ListView1.Items(1).ImageIndex = ImageList1.Images.Count - 1

'Load from file
Dim s As String = Application.StartupPath
Dim FileName As String = s.Substring(0, s.LastIndexOf("\"c) + 1) &
"help2.ico"
ImageList1.Images.Add(New System.Drawing.Icon(FileName))

'Set item 2 image
ListView1.Items(2).ImageIndex = ImageList1.Images.Count - 1

End Sub

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eK**************@tk2msftngp13.phx.gbl...
How are you adding them?
In what way are they corrupted?

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
When I display icons in controls from an imagelist, the icons are
"corrupted" if they are added from a resource (or a file) but are fine if I
add them using the designer at design time. I need to add the icons
dynamically at runtime.

How can you add the icons at runtime without corrupting the image?


Jul 21 '05 #3
The class at the following link will help you to extract a specific icon
from the Icon Resource.
http://www.codeproject.com/dotnet/MultiIcon.asp

Your code looks fine.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
Here's some code from my test project. I have an icon "help2.ico" that
contains all possible image sizes and formats. At design time, I add it
to
ImageList1. I also create ListView1 with 3 items in it, and add the icon
to
the project as an embedded resource.

When you run the project, the last two items have corrupted icons. It
looks
like the icons are being resized from a larger icon size. How do I tell
it
to use the correct icon size from the icon?

Code follows:
--------------

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Set image list
ListView1.SmallImageList = ImageList1

'Set item 0 image
ListView1.Items(0).ImageIndex = 0

'Load from resource
ImageList1.Images.Add(New
System.Drawing.Icon(System.Reflection.Assembly.Get ExecutingAssembly.GetManif
estResourceStream(Me.GetType, "help2.ico")))

'Set item 1 image
ListView1.Items(1).ImageIndex = ImageList1.Images.Count - 1

'Load from file
Dim s As String = Application.StartupPath
Dim FileName As String = s.Substring(0, s.LastIndexOf("\"c) + 1) &
"help2.ico"
ImageList1.Images.Add(New System.Drawing.Icon(FileName))

'Set item 2 image
ListView1.Items(2).ImageIndex = ImageList1.Images.Count - 1

End Sub

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in
message news:eK**************@tk2msftngp13.phx.gbl...
How are you adding them?
In what way are they corrupted?

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
> When I display icons in controls from an imagelist, the icons are
> "corrupted" if they are added from a resource (or a file) but are fine if > I
> add them using the designer at design time. I need to add the icons
> dynamically at runtime.
>
> How can you add the icons at runtime without corrupting the image?
>
>



Jul 21 '05 #4
Excellent. I've tested and it does resolve the problem.

Thanks Mick (and Matthew Hazlett).

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...
The class at the following link will help you to extract a specific icon
from the Icon Resource.
http://www.codeproject.com/dotnet/MultiIcon.asp

Your code looks fine.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
Here's some code from my test project. I have an icon "help2.ico" that
contains all possible image sizes and formats. At design time, I add it
to
ImageList1. I also create ListView1 with 3 items in it, and add the icon to
the project as an embedded resource.

When you run the project, the last two items have corrupted icons. It
looks
like the icons are being resized from a larger icon size. How do I tell
it
to use the correct icon size from the icon?

Code follows:
--------------

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Set image list
ListView1.SmallImageList = ImageList1

'Set item 0 image
ListView1.Items(0).ImageIndex = 0

'Load from resource
ImageList1.Images.Add(New
System.Drawing.Icon(System.Reflection.Assembly.Get ExecutingAssembly.GetManif estResourceStream(Me.GetType, "help2.ico")))

'Set item 1 image
ListView1.Items(1).ImageIndex = ImageList1.Images.Count - 1

'Load from file
Dim s As String = Application.StartupPath
Dim FileName As String = s.Substring(0, s.LastIndexOf("\"c) + 1) & "help2.ico"
ImageList1.Images.Add(New System.Drawing.Icon(FileName))

'Set item 2 image
ListView1.Items(2).ImageIndex = ImageList1.Images.Count - 1

End Sub

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote
in
message news:eK**************@tk2msftngp13.phx.gbl...
How are you adding them?
In what way are they corrupted?

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Carl Scarlett" <ab*@de.f.g> wrote in message
news:OF**************@TK2MSFTNGP12.phx.gbl...
> When I display icons in controls from an imagelist, the icons are
> "corrupted" if they are added from a resource (or a file) but are
fine if
> I
> add them using the designer at design time. I need to add the icons
> dynamically at runtime.
>
> How can you add the icons at runtime without corrupting the image?
>
>



Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Adrian | last post: by
reply views Thread by Tony Lugg | last post: by
4 posts views Thread by Carl Scarlett | last post: by
13 posts views Thread by Lou | last post: by
4 posts views Thread by randy1200 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.