C# Adding images to a list -
i'm trying add images used imagelist named "images1". i'm not in coding programs know rest of program working except fact "images1" not exist 2 last voids. searched resolve problem have difficulty find answer specific case.
how can make image list "images1" available private voids?
this code:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using system.collections; using system.globalization; using system.resources; using system.reflection; namespace booster_pack_2 { public partial class form3 : form { public form3() { initializecomponent(); } private void textbox1_textchanged(object sender, eventargs e) { list<image> images1 = new list<image>(); resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index1 = textbox1.text; bitmap image1 = (bitmap)rm.getobject(index1); picturebox1.image = image1; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index1)); } private void textbox2_textchanged(object sender, eventargs e) { resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index2 = textbox2.text; bitmap image2 = (bitmap)rm.getobject(index2); picturebox2.image = image2; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index2)); } private void textbox3_textchanged(object sender, eventargs e) { resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index3 = textbox3.text; bitmap image3 = (bitmap)rm.getobject(index3); picturebox3.image = image3; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index3)); } } }
put in proper scope. if need access in event handlers, make class member:
namespace booster_pack_2 { public partial class form3 : form { list<image> images1; public form3() { initializecomponent(); } private void textbox1_textchanged(object sender, eventargs e) { images1 = new list<image>(); resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index1 = textbox1.text; bitmap image1 = (bitmap)rm.getobject(index1); picturebox1.image = image1; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index1)); } private void textbox2_textchanged(object sender, eventargs e) { resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index2 = textbox2.text; bitmap image2 = (bitmap)rm.getobject(index2); picturebox2.image = image2; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index2)); } private void textbox3_textchanged(object sender, eventargs e) { resourcemanager rm = booster_pack_2.properties.resources.resourcemanager; string index3 = textbox3.text; bitmap image3 = (bitmap)rm.getobject(index3); picturebox3.image = image3; images1.add((image)booster_pack_2.properties.resources.resourcemanager.getobject(index3)); }
} }
i'd advise moving line: images1 = new list(); constructor instead, in case textbox1 isn't edited first.
Comments
Post a Comment