Relatively new to C #; I hope I just miss something simple.
I have a form called "Exercise1" that contains a window with the drawing "drawingArea" and a few buttons. Exercise1 constructor code is as follows:
public Exercise1() { InitializeComponent(); paper = drawingArea.CreateGraphics(); balloon = new Balloon("redBalloon", Color.Red, drawingArea.Width / 2, drawingArea.Height / 2, 30); paper.Clear(Color.White); balloon.Display(paper); } ...
"paper" and "balloon" are created as globals above the constructor for use in other form methods. Both "paper" and "balloon" work as initialized in the constructor in other methods defined in the form.
For some reason teams
paper.Clear(Color.White);
and
balloon.Display(paper);
To clear the image window and show a red ellipse, do not perform (at least, apparently). What gives?
UPDATE: I think I will like this site ... You guys are fast! @Nitesh: The constructor for Exercise1 is called from another form. The code is as follows:
private void button1_Click(object sender, EventArgs e) { int exSelector = (int)numericUpDown1.Value; switch (exSelector) { case 1: Exercise1 form1 = new Exercise1(); form1.Show(); break; ...
@Sean Dunford: Yes and yes, it is. @RBarryYoung: Played with this a bit, but no luck. Which command fires the Form_Load event for Exercise1?
UPDATE: This modified code works as expected:
public Exercise1() { InitializeComponent(); paper = drawingArea.CreateGraphics(); drawingArea.BackColor = Color.White; drawingArea.Paint += new PaintEventHandler(this.drawingArea_Paint); balloon = new Balloon("redBalloon", Color.Red, drawingArea.Width / 2, drawingArea.Height / 2, 30); } private void drawingArea_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.White); balloon.Display(e.Graphics); } ...
Thanks for the help!