473,765 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2024
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******** ******@TK2MSFTN GP12.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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Set image list
ListView1.Small ImageList = ImageList1

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

'Load from resource
ImageList1.Imag es.Add(New
System.Drawing. Icon(System.Ref lection.Assembl y.GetExecutingA ssembly.GetMani f
estResourceStre am(Me.GetType, "help2.ico" )))

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

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

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

End Sub

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:eK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.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******** ******@TK2MSFTN GP10.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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Set image list
ListView1.Small ImageList = ImageList1

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

'Load from resource
ImageList1.Imag es.Add(New
System.Drawing. Icon(System.Ref lection.Assembl y.GetExecutingA ssembly.GetMani f
estResourceStre am(Me.GetType, "help2.ico" )))

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

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

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

End Sub

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote
in
message news:eK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.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.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:%2******** ********@TK2MSF TNGP15.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******** ******@TK2MSFTN GP10.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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Set image list
ListView1.Small ImageList = ImageList1

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

'Load from resource
ImageList1.Imag es.Add(New
System.Drawing. Icon(System.Ref lection.Assembl y.GetExecutingA ssembly.GetMani f estResourceStre am(Me.GetType, "help2.ico" )))

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

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

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

End Sub

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote
in
message news:eK******** ******@tk2msftn gp13.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******** ******@TK2MSFTN GP12.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
49013
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 way to do this? This was easy to do in the old MFC. I can not find the answer in C#. I also need to embed an XML file into the resource and load it at run time. I am hoping once I figure out how to load an icon resource then loading an XML...
2
13200
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 changed "Build Action" for the file to "Embedded Resource" 3 - At the end of my constructor, I try to load an icon and it throws the following exception: Exception:
4
3731
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 valid until you called "DestroyIcon()". If you didn't, you had a leak. In C#, I need to load icons from unmanaged programs (.exe, dll) at run time and I want to make sure I'm not leaking resources, but it's not clear to me how to insure that I'm...
8
2282
by: Adrian | last post by:
How do I put an icon on a form using code? Thank you.
0
1496
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 icons are added to two ImageList objects which are bound to a ListView control, and everything looks great. I am saving the icons to a SQL Server table by using Icon.Save to a stream and assigning the byte array to the field, then loading them...
3
2758
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 icons are added to two ImageList objects which are bound to a ListView control, and everything looks great. I am saving the icons to a SQL Server table by using Icon.Save to a stream and assigning the byte array to the field, then loading them...
4
251
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 add the icons dynamically at runtime. How can you add the icons at runtime without corrupting the image?
13
2080
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 part of the .resx file. Its like VB6 when I could use load all my images from a resource file. Lou
4
6553
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 completely different. I overwrote the old ico file with the new ico file and re-ran the program. I still see the old logo at run-time. I right-clicked the project-> Add Existing Item-> added the new ico file. I set the build action to Embedded...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.