Using system.drawing; using system.collections; using system.windows.form; using system.data; using system.resources;
A summary description of Namespace WindowsResource {///
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#REGION Windows Form Designer The code ///
/// summary> private void InitializeComponent () {this.BtnWrite = new System.Windows.Forms.Button (); this.textGreeting = new System.Windows.Forms.TextBox (); this.btnRead = new System. Windows.Forms.Button (); this.textPassword = new System.Windows.Forms.TextBox (); this.textPurchase = new System.Windows.Forms.TextBox (); this.label1 = new System.Windows.Forms.Label (); This.Label2 = new system.windows.forms.label (); this.label3 = new system.windows.forms.label (); this.button1 = new system.windows.Forms.Button (); this. SuspendLayout (); // // btnwrite // this.btnwrite.location = new system.drawing.point (24, 200); this.btnwrite.name = "btnwrite"; this.btnwrite.tabindex = 0; this.btnwrite .Text = "Write resource file"; this.btnwrite.click = new system.eventhandler (this.btnwrite_click; /// textgreeting // this.textgreeting.location = new system.drawing.point (272, 48) This.TextGreeting.Name = "textgreeting"; this.textgreeting.tabindex = 1; this.textg Reeting.text = "textbox1"; // // btnread // this.btnread.location = new system.drawing.point (104, 200); this.btnread.name = "btnread"; this.btnread.tabindex = 2 "This.btnread.text =" Read the resource file "; this.btnread.click = new system.eventhandler (this.btnread_click); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////> 272, 88); this.TextPassword.name = "textpassword"; this.textpassword.tabindex = 3; this.textpassword.text = "textbox2"; // // textpurchase // this.textpurchase.location =
New system.drawing.point (272, 136); this.textpurchase.name = "textpurchase"; this.textpurchase.tabindex = 4; this.textpurchase.text = "textbox3"; // // label1 // this.label1 .Location = new system.drawing.point (154, 56); this.label1.name = "label1"; this.label1.size = new system.drawing.size (100, 18); this.label1.tabindex = 5 This.Label1.Text = "greeting"; // // label2 // this.label2.location = new system.drawing.point (154, 104); this.label2.name = "label2"; this.label2. Size = new system.drawing.size (100, 18); this.label2.tabindex = 6; this.label2.text = "passwordException"; // // label3 // this.label3.location = new system.drawing. Point (154, 144); this.label3.name = "label3"; this.label3.size = new system.drawing.size (100, 18); this.label3.tabindex = 7; this.label3.text = " Purchase "; // // Button1 // this.button1.location = new system.drawing.point (192, 200); this.button1.name =" button1 "; this.button1.size = ne w system.drawing.size (88, 23); this.button1.tabindex = 8; this.button1.text = "resourceReader"; this.button1.click = new system.eventhandler (this.button1_click); // / / Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (400, 293); this.Controls.add (this.button1); this.Controls .Add (this.label3); this.controls.add (this.label2); this.controls.add (this.label1); this.controls.add (this.TextPurchase); this.Controls.add (this.TextPassword This.Controls.add (this.btnread);
This.Controls.add (this.TextGreeting); this.controls.add (this.btnwrite); this.name = "form1"; this.text = "form1"; this.ResumeLayout (false);} #ENDREGION
///
Private void btnwrite_click (object sender, system.eventargs e) {resourceWriter RW = New ResourceWriter ("Greeting.Resources");
Bitmap B = New Bitmap ("HHW.GIF");
// Add Some strings to the file rw.addresource ("Greeting", "Welcome to Microsoft .NET Framework! Test"); rw.addresource ("PasswordException", "Sorry, That is not the correct password."); RW .AddResource ("purchase", "plechase"; rw.addresource ("Goodbye", "Thank you for visiting microsoft .net framework!"); Rw.addResource ("flag", b);
Rw.Generate (); rw.close ();
private void btnRead_Click (object sender, System.EventArgs e) {ResourceManager rm = ResourceManager.CreateFileBasedResourceManager ( "Greeting",, null "."); textGreeting.Text = rm.GetString ( "Greeting"); textPassword.Text = rm. GetString ("PasswordException"); TextPurchase.text = rm.getstring ("purchase"); RM.GetString ("Goodbye"); Bitmap B = (Bitmap) RM.GetObject ("flag"); this.backgroundimage = B;
}
private void button1_Click (object sender, System.EventArgs e) {ResourceReader rr = new ResourceReader ( "Greeting.resources"); String s = ""; // iterate through the reader, printing out the name-value pairs foreach (DictionaryEntry d IN rr) {s = "text" d.Key; if (s == "textgreeting") {textgreeting.text = D.Value.toString ();} if (s == "textpassword") {textPassword.text = D.Value.toString ();} if (s == "textpurchase") {textpurchase.text = D.Value.toString ();}} // close the reader r.close ();}}