By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Icon corruption when loading from a resource

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.