c# - PictureBox image not displayed by Form.Shown call -


i have form containing tablelayoutpanel has 1 row , 2 columns.

column 1 contains panel contains picture box. column 2 text box.

i display form , add text textbox 1 character @ time. works except picturebox image isn't displayed until textbox has finished populating.

class program {     static void main(string[] args)     {         mainform mainform = new mainform();          formshown shown = new formshown(mainform);          mainform.shown += new eventhandler(shown.mainform_shown);          mainform.showdialog();     } }  class formshown {     mainform mainform;      public formshown(mainform amainform)     {         mainform = amainform;     }      public void f1_shown(object sender, eventargs e)     {         mainform.addtext("hello!");     } }  public partial class mainform : form {     public mainform()     {         initializecomponent();          picturebox.image = myapp.properties.resources.myimage;     }      public void addtext(string text)     {         foreach (char c in text)         {             textbox.text += c;             textbox.refresh();             system.threading.thread.sleep(100);             textbox.selectionstart = textbox.text.length;         }     } }    

i'd hoped setting image in code resources quick enough, , expected picturebox loaded form.shown event - wrong think this?

i've tried setting image in design view opposed in code, same results.

is there different event should using? believe shown last called.

thanks!

if know windows form event life cycle can understand problem getting. image , other controls drawn when form being painted , paint event raised @ end. so, means application not draw control or graphic until process not done.

you should call addtext() method in different process.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -