473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1987
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ed Sutton | last post by:
I have been searching for how to get an icon resource and load it into an ImageList. I added an *.ico file to my project and set the files "Build Action" to "Embedded Resource". Is there any easy...
2
by: Ed Sutton | last post by:
What's the trick to loading an icon from the embedded resources? Here are the steps I have taken: ------------------------- 1 - I added a file named "FOLDER01.ICO" to my solution project 2 - I...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
8
by: Adrian | last post by:
How do I put an icon on a form using code? Thank you.
0
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
4
by: Carl Scarlett | last post by:
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...
13
by: Lou | last post by:
if I add a new item (Solution Items) to my project and its an icon(.ico), how can I reference that file when I am coding, Do I have to also add it to an image control, I don't want the file to be...
4
by: randy1200 | last post by:
I have a Windows application that previously had the company logo "MyCompany.ico" added to the upper left-most corner. The company has since issued a new version of "MyCompany.ico" that looks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.