Show message from string table in C#

1. Run Microsoft Visual Studio 2010 and create a new windows application(File->New->Project)

2. Select Windows FormsApplication and enter application Name into Name field “TestMessage”

3.  Add a button from Toolbox, enter ‘Show Message’ into Text property, ‘btnShowMessage’ into Name property

4. Double click on the button to go to the class file

5. Add tow reference:

using  System.Resources;

using System.Reflection;

6. Go to the design view and right click on the project solution name in solution view, select Add->New Item, select Resource File and click on ‘Add’ button. A file named ‘Resource1.resx’ will add to your project

7. Double click on the resource file and enter “This is a test” into value field. default name field is String1. save the file

8. Add following code into Form1 class scope:

public partial class Form1 : Form
    {

        private static ResourceManager RM;
       
        public static void initialise()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            RM = new ResourceManager(“TestMessage.Resource1”, assembly);
        }
        public static string Getstring(string key)
        {
            return RM.GetString(key);
        }

}

9. To initialize the file add following code into default constractor of the class:

public Form1()
        {
            InitializeComponent();
            initialise();

        }

10. Double click on the button and add the code:

private void btnShow_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Getstring(“String1”));
        }

11. Compile and run the project, click on the button.It will display message from string table

One Response

  1. গ্রামীন ফোন অপেরা মিনিকে সাথে নিয়ে ইন্টারন্যাট উৎসব নামে একটি ক্যাম্পেইন শুরু করতে যাচ্ছে। যার উদ্দেশ্য হল সারাদেশে স্কুল কলেজের শিক্ষার্থীদের ইন্টারনেট ব্যবহারে উৎসাহিত করা। আমার কাছে ব্যপারটা অনেকটা ঢাল তরবারি বিহীন নিধীরাম সরদার তৈরী করার মত মনে হয়েছে। কারন যে দেশের ইন্টারনেট সেবা এখনও মান্দাত্তা আমলের।

Leave a comment