0% found this document useful (0 votes)
22 views

To Create A Simple Visual Studio Project With String and Menu Resources

Uploaded by

aamirshahad3321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

To Create A Simple Visual Studio Project With String and Menu Resources

Uploaded by

aamirshahad3321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

To create a simple Visual Studio project with string and menu resources, let's use a C# Windows Forms

application as an example. Below are the steps to create the project, add the resources, and run the
application.

Step 1: Create a New Windows Forms Project

1. Open Visual Studio.

2. Create a new project by selecting File > New > Project.

3. In the Create a new project dialog, choose Windows Forms App (.NET) from the list of
templates.

4. Name your project (e.g., StringAndMenuResourceApp) and click Create.

Step 2: Add String Resources

1. Right-click on your project in the Solution Explorer.

2. Select Add > New Item.

3. Choose Resource File and name it Resources.resx. Click Add.

4. The Resource Designer will open. Add string resources by clicking on the drop-down arrow next
to Add Resource and selecting Add New String.

5. Add two strings:

 Name: MenuFile, Value: File

 Name: MenuEdit, Value: Edit

Step 3: Add a MenuStrip to the Form

1. Open Form1.cs [Design].

2. From the Toolbox, drag and drop a MenuStrip onto the form.

3. Click on the MenuStrip to edit its items. Add two top-level items and name them:

 First item: Name it fileToolStripMenuItem, Text: leave it empty (we'll set it in code).

 Second item: Name it editToolStripMenuItem, Text: leave it empty (we'll set it in code).

Step 4: Set MenuStrip Items from Resources

1. Open Form1.cs.

2. Modify the Form1 constructor to load the menu item text from the resources.
csharp

Copy code

using System; using System.Windows.Forms; namespace StringAndMenuResourceApp { public partial


class Form1 : Form { public Form1() { InitializeComponent(); // Set menu item text from resources
fileToolStripMenuItem.Text = Properties.Resources.MenuFile; editToolStripMenuItem.Text =
Properties.Resources.MenuEdit; } } }

Step 5: Run the Application

1. Build the project by selecting Build > Build Solution.

2. Run the application by pressing F5 or clicking the Start button.

Final Notes

 Ensure that the resource names in Properties.Resources match exactly with what you defined in
the Resources.resx file.

 The Properties.Resources.MenuFile and Properties.Resources.MenuEdit will automatically map


to the string resources you added.

You might also like