Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

Resources in C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 16 Jan 2008 15:00 GMT
Can someone help me using resources in C#/.NET 2005?

I've found numerous examples on the internet. They all seem to refer to
resources files ending in ".resource". why? When I add a new resource
file, the filetypes are ".resx". Or some others want me to use resgen..
I'd rather stay out of the command prompt, and I'm sure it must be
possible to do everything through the IDE.

I'd basically like to have "StringResource.resx" and
"StringResource.ca-FR.resx", and use these from within my code. Right
now, with these in my Properties folders, and using the following code,
it can't find the resource.

ResourceManager resource = new ResourceManager("StringResource",
Assembly.GetExecutingAssembly());

Thanks,
Greg
Kevin Spencer - 16 Jan 2008 15:41 GMT
Right-Click the Project and select Properties. Go to the Resources tab. Add
a file resource. Then you can access it in the app via

Properties.Resources.Resourcename

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Can someone help me using resources in C#/.NET 2005?
>
[quoted text clipped - 14 lines]
> Thanks,
> Greg
Greg - 16 Jan 2008 21:08 GMT
Thanks! Do I need to do this for each file/locale, or just for the base
file?

Greg

-----Original Message-----
From: Kevin Spencer [mailto:unclechutney@nothinks.com]
Posted At: January 16, 2008 10:42 AM
Posted To: microsoft.public.dotnet.framework.windowsforms
Conversation: Resources in C#
Subject: Re: Resources in C#

Right-Click the Project and select Properties. Go to the Resources tab.
Add a file resource. Then you can access it in the app via

Properties.Resources.Resourcename

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Can someone help me using resources in C#/.NET 2005?
>
> I've found numerous examples on the internet. They all seem to refer
> to resources files ending in ".resource". why? When I add a new
> resource file, the filetypes are ".resx". Or some others want me to
use resgen..
> I'd rather stay out of the command prompt, and I'm sure it must be
> possible to do everything through the IDE.
[quoted text clipped - 9 lines]
> Thanks,
> Greg
Steven Cheng[MSFT] - 17 Jan 2008 03:47 GMT
Hi Greg,

The way Kevin mentioned can help you add resource into the project's main
resource file. You can also add your own resx file into project and read
resource from them in code. Just like what you do in your first reply:

** add a new resx file into project

** add resource items into the resx file

** use ResourceManager to retrieve resource items from it.

The problem that you didn't get anything is due to the following reason:

For .NET C# project, VS project will use project name as its "default
namespace", therefore, if you add a certain resx file into the project,
suppose "StringResource.resx" and the project name is
"WindowsFormsApplication1", the full name of the resource file is

"WindowsFormsApplication1.StringResource" rather than "StringResource"

e.g.

====================

       private void button1_Click(object sender, EventArgs e)
       {
           ResourceManager rm = new
ResourceManager("WindowsFormsApplication1.StringResource",
typeof(Form1).Assembly);
           string str1 =rm.GetString("String1");
           MessageBox.Show(str1);
       }
=====================

You can try it on your side to see whether it works.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Greg" <thefish@nospam.nospam>
>References: <000901c85850$9f687470$6e6f100a@ncr.dfompo.ca>
<uTvi2YFWIHA.1184@TK2MSFTNGP04.phx.gbl>
>Subject: Re: Resources in C#
>Date: Wed, 16 Jan 2008 16:08:58 -0500

>Thanks! Do I need to do this for each file/locale, or just for the base
>file?
[quoted text clipped - 39 lines]
>> Thanks,
>> Greg
Kevin Spencer - 17 Jan 2008 12:31 GMT
Hi Greg,

Sorry, I didn't see that you're using Localization. Visual Studio's Resource
Designer can be used for localized resources as well. The following article
explains how:

http://technet.microsoft.com/en-us/library/aa992030.aspx

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Thanks! Do I need to do this for each file/locale, or just for the base
> file?
[quoted text clipped - 39 lines]
>> Thanks,
>> Greg

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.