473,765 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why so hard to load icon from embeded resource?

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.I CO" 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:
"Resource 'myProject.frmM ain.FOLDER01.IC O' could not be found in class
'myProject.frmM ain'."
namespace myProject
{
public class frmMain : System.Windows. Forms.Form
{
public frmMain()
{
// This throws an exception
Icon = new Icon(typeof(frm Main),
"myProject.frmM ain.FOLDER01.IC O");
}

Thanks in advance for any tips or suggestions,

-Ed

Nov 15 '05 #1
2 13200
Never mind. I found a syntax that works. These two lines will work:

Icon = new Icon(typeof(frm Main), "FOLDER01.ICO") ;
Icon = new Icon(GetType(), "FOLDER01.ICO") ;

When I tried to match the syntax in the Petzold book, "Programmin g Windows
with C#", for some reason, the following throws the exception I mentioned.

Icon = new Icon(typeof(frm Main), "frmMain.FOLDER 01.ICO");

Oh well, move on.

-Ed

Ed Sutton wrote:
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.I CO" 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:
"Resource 'myProject.frmM ain.FOLDER01.IC O' could not be found in class
'myProject.frmM ain'."
namespace myProject
{
public class frmMain : System.Windows. Forms.Form
{
public frmMain()
{
// This throws an exception
Icon = new Icon(typeof(frm Main),
"myProject.frmM ain.FOLDER01.IC O");
}

Thanks in advance for any tips or suggestions,

-Ed

Nov 15 '05 #2
And another problem I was having is that the resource name is * case
sensitive *. It must match the case sensitivity of the embedded resource
file name you added to your solution.

For example, if you added a file named "FOLDER01.I CO" to your solution and
made it an embedded resource. The following works:

Icon = new Icon(typeof(frm Main), "FOLDER01.ICO") ;

This will fail:
Icon = new Icon(typeof(frm Main), "folder01.ico") ;

This somehow suprised me. I think this is the first time, using a Windows
programming language, that I have run into file name case sensitivity. I
suppose that once it is embedded as a resource, it is no longer just a file
name.

-Ed
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3593
by: Greg | last post by:
Set Up Error - Failed to load resources from resource file Please check your set up. This plesently cordal and verbose error is greeting me in a very random and unpredictable way in a current VB .NET stand alone project I am doing (some times the program runs for 10 minutes, other times, I get the error right away). Has anyone seen this error in a VB.Net program? Any
3
7231
by: Ramani | last post by:
Hi, We are running a ASP .NET application on Win2K server (.NET framework 1.1) I have recently started getting this error - Failed to load resources from resource file. I would like to understand what causes this error. It is a multi-language app and in Application_BeginRequest we do Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages);
0
1749
by: Kevin P | last post by:
Hi News Group, In an application written in C# and VS.Net using Dotnet Framework 1.1.4322 on XP and Win 2000 machines, we randomly get the error "Failed to load resources from resource file. Please check your setup." Although it is a random occurrance, it happens at the exact same location in the progran every time. At the time of this error, the monitor starts flickering white at a high frequency and CPU usage pegs out at 100%. The only...
0
2326
by: Paul | last post by:
I have an existing application that has been installed and running for several months. I recently made a minor change to this application. When the application is installed on the user machine and then run, I get the following error: Setup Error Failed to load resources from resource file. Please check your setup. The application was installed on a Windows XP SP2 machine. I have un-installed the .NET Framework 1.1 and latest hot-fix...
3
7799
by: Preference | last post by:
Hello, I am developing a .NET application in managed C++. Until now we have executed without problems in a lot of different computers. But a few days ago we detect a problem in some laptops. In all cases the system was XP SP2 and ..NET Framework 1.1. The problem appears initializing the application. A message box with the text 'Failed to load resources from resource file. Please check your Setup' appears and the application does not...
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...
0
1958
by: Wal Turner | last post by:
Hi. The following error I seemingly get at random times when my application is loading. ************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at...
2
10602
by: Paul Cheetham | last post by:
Hi, I am trying to load a custom cursor from my programs resources. I have successfully included the cursor resource, and I have confirmed that the name I am using is correct. Below is the code I am using to try and load the cursor - which always returns null. I have tried using LoadImage and LoadCursor with the same result.
4
2466
by: bclegg | last post by:
Hi, I am getting the above error when start my application which I deployed successfully. The msi was produced using a .net launch project. I can't see how to dig deeper to find out what is failing to load. I have looked at the manifest with ildasm but am none the wiser. Does anybody know how to diagnose this sort of problem?
0
1196
by: Pitaridis Aristotelis | last post by:
I know how to extract an embeded resource from a file but does anyone how to import an embeded resource to a file?
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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
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...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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

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.