Csharp/C Sharp/GUI Windows Form/ResourceWriter — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:32, 26 мая 2010

Make a new *.resources file.

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;

public class MainClass {
    public static void Main() {
        ResourceWriter rw = new ResourceWriter(@"C:\myResources.resources");
        // Add 1 image and 1 string.
        rw.AddResource("happyDude", new Bitmap("happyDude.bmp"));
        rw.AddResource("welcomeString", "Hello new resource format!");
        rw.Generate();
        rw.Close();
    }
}


Resource file generator

using System;
using System.Resources;
class LanguageResourceWriter {
    public static void WriteEnglishResources() {
        ResourceWriter rw = new ResourceWriter("Eng.resources");
        rw.AddResource("Greeting", "Hello");
        rw.AddResource("Program Name", "AAA");
        rw.AddResource("Author", "T");
        rw.Close();
    }
    public static void WriteSpanishResources() {
        ResourceWriter rw = new ResourceWriter("Span.resources");
        rw.AddResource("Greeting", "Hola");
        rw.AddResource("Program Name", "BBB");
        rw.AddResource("Author", "FFF");
        rw.Close();
    }
    public static void WriteFrenchResources() {
        ResourceWriter rw = new ResourceWriter("French.resources");
        rw.AddResource("Greeting", "Bonjour");
        rw.AddResource("Program Name", "DDD");
        rw.AddResource("Author", "EEE");
        rw.Close();
    }
    public static void Main() {
        WriteEnglishResources();
        WriteSpanishResources();
        WriteFrenchResources();
    }
}


Writing a resource file programmatically.

using System;
using System.Resources;
class MainClass {
    public static void Main() {
        ResourceWriter rw = new ResourceWriter("English.resources");
        rw.AddResource("PgmName", "AAA");
        rw.AddResource("PgmVer", 1.0);
        rw.AddResource("PgmAuthor", "VVVV");
        rw.Close();
    }
}