0

In asp.net I use like this:

  gridView_Desti.Columns["CODE_DEST"].Caption = (string) HttpContext.GetGlobalResourceObject("Client", "Code_Dest");

How can I do the same thing on WinForm ?

Client is the resource name file --> Client.resx
Code_Dest is string on Client.resx --> string Code_Dest, value Code Destinataire

0

4 Answers 4

3

You should have an auto-generated class called Resources in the Properties namespace of your project. Each resource is exposed as a property in that class.

Sign up to request clarification or add additional context in comments.

Comments

2

You can do :

Client.ResourceManager.GetString("Code_Dest");

Depending on the culture, it will look for the string in Client.en-US.resx (if en-US is your current culture) and if it fail, in Client.resx.

You can also acces like this (Code_Dest must be in Client.resx) :

Client.Code_Dest;

Comments

0
  1. Add new item -> Resources i.e 'Resources1.resx'
    1. Put necessary Resources Name & value ie string resources -> 'YourResourcesName' value whatever.
    2. Access its value with Resources1.YourResourcesName

Hope this help,

Comments

0

If you don't have the namespace in, then prepend with "Properties" C# as so:

Properties.Resources1.YourResourcesName

Makes your code so much cleaner using the resx file. As an example, I have a DataGridViewImageColumn and assigned an image to it (from VS Image Library - the image is a .png file):

colAddNewItem.Image = Properties.Resource1.Add_16x;

FYI, in VB.Net it's

Resources.Resources1.YourResourcesName

There are many other ways, but this is the simplest, cleanest & preferred method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.