c# - Controlling a PictureBox from a class -
i have little project in c#, (windows forms application). have on form 77 pictureboxes (picturebox1, picturebox2, picturebox3, ...) , want control them new class (access.cs), declaring new 1 picturebox in class control pictures.
because long if pass through each picturebox , add click method , copy + paste code , change picturebox number each time.
i've set pictures public , tried following code:
access.cs:
using system.windows.forms; public class access { picturebox picbox = new picturebox(); public void pictureclicked() { picbox.image = properties.resources.apple; } }
form1.cs:
private void picturebox1_click(object sender, eventargs e) { access ac = new access(); ac.pictureclicked(); }
but code didn't work!!
i dont want try send object access class:
private void picturebox1_click(object sender, eventargs e) { access ac = new access(); ac.pictureclicked(sender); } public void pictureclicked(object sender) { picbox = (picturebox)sender; picbox.image = properties.resources.apple; }
Comments
Post a Comment