のインスタンスを作成:問題私は、Visual Studio 2010年には以下のクラスを作成しましクラス
public class Bat : Form1
{
public int BatLocation;
public void draw()
{
Pen batPen = new Pen(Color.Black);
batPen.Width = 10;
playArea.DrawRectangle(batPen, BatLocation, (picPlayArea.Height - 30), 50, 10);
}
}
をしかし、私はクラスのインスタンスを作成しようとすると、私は私を専門家の意見、スタックオーバーフロー例外を取得無限ループまたは無限再帰を持たないようにしてください。私は以下のように、インスタンスに二つの異なる方法を作成しようとした:
Bat bottomBat;
bottomBat = new Bat();
と
Bat bottomBat = new Bat();
しかし、私はプログラムを実行しようとすると、両方の方法は、同じエラーを返します。また、public
修飾子の有無にかかわらずクラス定義を試しました。
私はプログラミングに慣れていないので、何がこの問題を引き起こしているのか分かりません。私は何か間違っているのですか?
編集:Bat
クラスのコードは、現時点では私が持っているすべてです、それのための特定のコンストラクタを作成していない...私は必要だと思いませんでしたか?
public partial class Form1 : Form
{
// Define various objects for the game
public Graphics playArea;
Bat bottomBat = new Bat();
public Form1()
{
InitializeComponent();
// Create instances of objects
playArea = picPlayArea.CreateGraphics();
//bottomBat = new Bat();
// Delegate the mouseMove event for picPlayArea
picPlayArea.MouseMove += new MouseEventHandler(picPlayArea_MouseMove);
}
private void picPlayArea_MouseMove(object sender, MouseEventArgs e)
{
bottomBat.Location = e.X;
}
private void btnExit_Click(object sender, EventArgs e)
{
string msg = "Are you sure you want to exit?",
title = "Confirm Exit";
DialogResult res = MessageBox.Show(msg, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (res == DialogResult.Yes)
{
Environment.Exit(0);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
// This is where most of the functionality is executed within the game
playArea.Clear(Color.White);
}
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
}
十分な情報がここにありません。ただし、例外的な状況で、あなたはこのように、この問題を解決することができます。クラスのすべてのコンストラクタだけでなく、そのベースクラスのコンストラクタのコードを投稿できますか? (あなたがBCLクラスであるベースクラスにヒットしたら停止することができます) – Ani
あなたが投稿したコード( 'playArea'を参照している行を引いたもの)は私のためにうまくいきます。そのため問題は、ポスト。 –
私はForm1クラスのコードを要求通りに追加しました –