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

  • Home
  • SEARCH
  • 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 7588257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:52:43+00:00 2026-05-30T19:52:43+00:00

Continuation of thread: C# Invalidate troubles . I created the class but now I

  • 0

Continuation of thread: C# Invalidate troubles. I created the class but now I get an Error 2 Embedded statement cannot be a declaration or labeled statement. And I am trying to create the “Car” by Car aCar = new Car(50,100); that is where I am getting the error.
Thanks for the suggestions.

  class Car
    {
     private Pen pen1 = new Pen(Color.Blue, 2F);
     private Pen pen2 = new Pen(Color.Green, 2F);
     int cost = 0; 
      int x, y;
      Graphics g;

public Car(int x, int y)
{
    this.x = x;
    this.y = y;
}

public void printCar()
{

    g.DrawEllipse(pen1, x, y, 30, 30);
    g.DrawEllipse(pen1, x + 100, y, 30, 30);
    g.DrawRectangle(pen2, x - 5, y + 50, 140, 50);
    g.DrawLine(pen2, x + 15, y + 50, x + 30, y + 90);
    g.DrawLine(pen2, x + 30, y + 90, x + 90, y + 90);
    g.DrawLine(pen2, x + 90, y + 90, x + 110, y + 50);
    // Create string to draw.
    String drawString = "Price: " + (cost).ToString("C");
    // Create font and brush.
    Font drawFont = new Font("Arial", 16);
    SolidBrush drawBrush = new SolidBrush(Color.Black);
    // Create point for upper-left corner of drawing.
    PointF drawPoint = new PointF(50, 95);
    // Draw string to screen.
    g.DrawString(drawString, drawFont, drawBrush, drawPoint);


} 

public partial class Form1 : Form
{

    private Pen pen1 = new Pen(Color.Blue, 2F);
    private Pen pen2 = new Pen(Color.Green, 2F);

    private double cost ;
    private int days = 0;
    private double air;
    private double automatic;
    int count;
    int m = 50;
    Car aCar = new Car(50, 60);

    public Form1()
    {

        InitializeComponent();

        days = int.Parse(textBox1.Text);

    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox1.SelectedItem.ToString() == "Van")
        {
            cost = 110;
            label1.Text = "The Cost of van per day" + (cost).ToString("C");
            textBox1.Text = "1";
            textBox1.Focus();
        }
        else if (comboBox1.SelectedItem.ToString() == "Car")
        {

            cost = 85.20;
            label1.Text = "The Cost of car per day" + (cost).ToString("C");
            textBox1.Text = "1";
            textBox1.Focus();
        }
        else
        {
            cost = 135;
            label1.Text = "Van" + (cost).ToString("C");
            textBox1.Text = "1";
            textBox1.Focus();
        }

    }

    private void button1_Click(object sender, EventArgs e)
    {
        count++;
        button1.Text = "Move";
        pictureBox1.Invalidate();
        if(count == 2)
            button1.Text = "Reset";
        if (count == 3)
        {
            textBox1.Text = "0";
            count = 0;
            comboBox1.Text = "select type of vehical";
            checkBox1.Checked = false;
            checkBox2.Checked = false;

        }
    }
    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
       e.Graphics.Clear(Color.White);

       if (count == 1)

       aCar.printCar();

      if (count == 2)

}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
  • 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-05-30T19:52:44+00:00Added an answer on May 30, 2026 at 7:52 pm

    You have to pass the Graphic object you are getting from the Paint event:

    Public void printCar(Graphic g)
    {
      // etc, etc
    }
    

    So that when you call it:

    aCar.printCar(e.Graphics);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

continuation of the issue How get array in linq to entity? but now is
How can I run each call for loop in another thread, but continuation of
This is a continuation question from a previous question I have asked I now
This question is a continuation of this thread : In short: To solve my
This thread is the continuation of the below thread Trigger Windows Service when the
This question is a continuation of a previous thread to compare two lists with
In continuation with my problem here , I created a test app that uses
A continuation from this question I need a SQL statement that returns the number
This is kind of continuation of this thread iphone how to go to the
In continuation to my question asked here , i have created a test app

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.