Thursday, March 13, 2014

Resourcees Writer and Management Class in C Sharp




Make a Windows form application in which manage and write resources by using Resources.

ResourceWriter Code:

usingSystem.Resources;
namespacewriting_resources
{
classProgram
    {
staticvoid Main(string[] args)
        {
try
            {
ResourceWriterrw = newResourceWriter("References.resources");
Imageimg;
img = Image.FromFile("Butterfly.jpg");
rw.AddResource("FirstImage", img);
rw.AddResource("FirstName", "First");
rw.AddResource("FirstPhone", "00112233");
img = Image.FromFile("Child.jpg");
rw.AddResource("SecondImage", img);
rw.AddResource("SecondName", "Second");
rw.AddResource("SecondPhone", "23423");
img = Image.FromFile("Bike.jpg");
rw.AddResource("ThirdImage", img);
rw.AddResource("ThirdName", "Third");
rw.AddResource("ThirdPhone", "2134");
img = Image.FromFile("Smile.jpg");
rw.AddResource("FourthImage", img);
rw.AddResource("FourthName", "Fourth");
rw.AddResource("FourthPhone", "4134");
Console.WriteLine("Resources Successfully writed");
rw.Close();
            }
catch (Exception ex)
            {
Console.WriteLine(ex.Message);
            }
        }
    }
}




Resource Manager Code:

usingSystem.Resources;
usingSystem.Reflection;
usingSystem.Collections;

namespaceResourcesManager
{
publicpartialclassForm1 : Form
    {
public Form1()
        {
InitializeComponent();
        }
ResourceManagerrm;
privateAssembly ass;
privateArrayList phones = newArrayList();
privatevoid button1_Click(object sender, EventArgs e)
        {
ass = Assembly.GetExecutingAssembly();
rm = newResourceManager("ResourcesManager.References", ass);
for (int count = 1; count<=4; count++)
            {
this.list_name.Items.Add(rm.GetString(count+"Name"));
this.img_List.Images.Add((Image)rm.GetObject(count+"Image"));

this.phones.Add(rm.GetString(count+"Phone"));
            }
pic_image.Image=this.img_List.Images[0];
this.list_name.SelectedIndex=0;
this.phone_list.Text=(string)this.phones[0];
this.btnnext.Enabled=true;
        }
privatevoidlist_name_SelectedIndexChanged(object sender, EventArgs e)
        {
this.phone_list.Text = (string)this.phones[this.list_name.SelectedIndex];
this.pic_image.Image=this.img_List.Images[this.list_name.SelectedIndex];
        }
privatevoidbtnnext_Click(object sender, EventArgs e)
        {
int index = this.list_name.SelectedIndex;
if (index < 4)
            {
index += 1;
this.list_name.SelectedIndex = index;
            }
else
            {
index+=0;
this.list_name.SelectedIndex=index;
            }}
privatevoid Form1_Load(object sender, EventArgs e){
        }
    }
 


1 comment:

  1. Best coin casino bonuses - Casinoowed
    These 온카지노 are the best bonuses in the online casino and include a top deposit bonus, หารายได้เสริม a free spins bonus, and 인카지노 an offer on slots and video poker. The

    ReplyDelete