首页 > 解决方案 > 我不断收到 InitializeComponent(); 我的代码中的错误

问题描述

using System.Drawing;
using System.Windows.Forms;
using PaddleClass;

namespace Form1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Paint += Form1_Paint;
        this.Invalidate(); /// this fires Paint event
        this.BackColor = System.Drawing.Color.Black;
    }
    Pen red = new Pen(Color.Red);
    Pen green = new Pen(Color.Green);

    System.Drawing.SolidBrush fillRed = new System.Drawing.SolidBrush(Color.Red);
    System.Drawing.SolidBrush fillYellow = new System.Drawing.SolidBrush(Color.Yellow);

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawRectangle(red, 100, 0, 220, 90); //(xpos., ypos., sizex, sizey)
        e.Graphics.DrawEllipse(green, 100, 0, 220, 90); //(xpos., ypos., sizex, sizey)
    }

    BallClass.Ball b = new BallClass.Ball(140, 510, 30, 30, 1, 1);
    BallClass.Ball b2 = new BallClass.Ball(140, 500, 10, 10, 1, 1);
    PaddleClass.Paddle p = new Paddle(140, 510, 30, 30);
    BrickClass.Brick br = new BrickClass.Brick(20, 20, 30, 30);

} 
}

我已经尝试了我所知道的一切,但我无法通过这个错误。每次我运行此代码时,都会出现以下错误:当前上下文中不存在名称“InitializeComponent”。拜托,有人可以告诉我发生了什么吗?

标签: c#initializecomponent

解决方案


推荐阅读