Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:16:06+00:00 2026-06-12T13:16:06+00:00

Relatively new to C#; hopefully I’m just overlooking something simple. I have a form

  • 0

Relatively new to C#; hopefully I’m just overlooking something simple.

I have a form named ‘Exercise1’ which contains a picture box called ‘drawingArea’ and a few buttons. The code for the constructor of Exercise1 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 the other methods on the form. Both ‘paper’ and ‘balloon’ work as initialized in the constructor in the other methods defined on the form.

For whatever reason, the commands

paper.Clear(Color.White);

and

balloon.Display(paper);

Which should clear the picture box and show a red ellipse, don’t execute (at least visibly). What gives?

UPDATE:
Think I’m going to like this website… You guys are quick!
@Nitesh: The constructor for Exercise1 is called from another form. 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: Was playing around with that a bit, but had no luck. What command triggers a Form_Load event for Exercise1?

UPDATE: This altered 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 all the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:16:07+00:00Added an answer on June 12, 2026 at 1:16 pm

    You cannot do drawing in the constructor. To do proper drawing, you need to have the form shown on the screen. You can try using the Shown event to do your rendering (this may get lost when the form is redrawn, though).

    Usually the best way is to set whatever flags you need in the constructor and then use the Paint event of the form to do all painting. Later on, when you need to repaint something, set up whatever state needs to be rendered, invalidate your form (this results in a Paint event) and then you can repaint the new state.

    If you try to do customized drawing (outside your Paint event) you’ll run the risk of things randomly going blank or your drawing may disapper when you resize/minimize your form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to JQuery and would like to try something. I just followed
Relatively new to rails, I'm working on a simple rails app for a few
Im relatively new to the Android world but I have a quick question. I
I am new to using QT and relatively new to C++. I have a
I am relatively new to .NET/C#/WPF/XAML. I have noticed sometimes controls seem to be
I am relatively new to IPhone coding, although I have reached the point of
Hopefully this is relatively simple. After I perform a LINQ query on a DataTable
Im relatively new to PHP but have realized it is a powerfull tool. So
I have been testing events API against a relatively new account (created June 13,
Relatively new rails programmer here, so bear with me. I have an app where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.