winforms - Picturebox and button click -


ran confusing problem. need make fishtank in windows forms. every time button clicked, fish appear. thought putting code in button_click function. problem picturebox image doesn't appear when click button.

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms;  namespace windowsformsapplication1 {     public partial class form1 : form     {         public form1()         {             initializecomponent();         }          private void form1_load(object sender, eventargs e)         {             backcolor = system.drawing.color.lightblue;         }          private void button1_click(object sender, eventargs e)         {                      //picturebox pb = new system.windows.forms.picturebox();             picturebox pb = new picturebox();             pb.image = image.fromfile("c:\\users\\elonas\\desktop\\fishtank\\photo\\fish_right.png");             pb.location = new point(300, 300);         }     } } 

every time create control (pb, in case), have add controls collection of form before can see it.

you can replace pb.image in picturebox instead of creating new picturebox every mouse click. still need add form's controls collection when create new (or create in designer).


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -