.net - How to make a method run on startup in C# -


i'm trying make method draws background of picture box when first open application. there way this?

i have tried

private void form1_load(object sender, eventargs e) {     drawbackground();  }  public void drawbackground()          {             graphics simwindow = pictureboxsimdisplay.creategraphics();              solidbrush brush = new solidbrush(color.green);              simwindow.fillrectangle(brush, 0, 211, 491,5);         } 

but not working.

i override forms onpaint method, way background you draw on redrawn when ever form repainted including initial load, if adding image or bitmap should use form load event others have stated.

from above link:

the onpaint method overridden repaint image each time form painted; otherwise image persist until next repainting

.


give try. found using onpaint method little erratic on initial load, if use timer(100ms) invalidate form works fine every time.

protected override void onpaint(painteventargs e) {     base.onpaint(e);     drawbackground();  }  public void drawbackground() {     graphics simwindow = pictureboxsimdisplay.creategraphics();     solidbrush brush = new solidbrush(color.green);     simwindow.fillrectangle(brush, 0, 211, 491, 5);     simwindow.dispose(); // don't forget dispose graphic object }  private void form1_load(object sender, eventargs e) {     timer1.start(); }   private void timer1_tick(object sender, eventargs e) {     timer1.stop();     invalidate(); }  

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -