我最近開始「學習」C#。目前我正在爲學校項目做某種遊戲。我想在表格上畫一個圓圈。我添加了一個時間,每個新的圓圈每1000毫秒繪製一個隨機的形式。但是當我開始我的表單時,並沒有真正發生。定時器啓動事件
命名空間Vezba_4 {
public partial class Form1 : Form
{
// attempt is when you try to "poke" the circle
bool attempt = false;
int xc, yc, Br = 0, Brkr = 0;
Random R = new Random();
public Form1()
{
InitializeComponent();
timer1.Start();
}
// Br爲界該玩家已成功地 「戳」 的數量。 Brkr是遊戲畫面上出現的圈子總數。
private void timer1_Tick(object sender, EventArgs e)
{
Refresh();
SolidBrush cetka = new SolidBrush(Color.Red);
Graphics g = CreateGraphics();
xc = R.Next(15, ClientRectangle.Width - 15);
yc = R.Next(15, ClientRectangle.Height - 15);
g.FillEllipse(cetka, xc - 15, yc - 15, 30, 30);
Brkr++;
Text = Br + "FROM" + Brkr;
attempt = false;
g.Dispose();
cetka.Dispose();
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (attempt == false)
{
if ((e.X - xc) * (e.X - xc) + (e.Y - yc) * (e.Y - yc) <= 225) Br++;
Text = Br + " FROM " + Brkr++;
}
attempt = true;
}
你在哪裏開始一個計時器?當你調試這個時,計時器的tick事件是否被調用? – David
確保您的計時器在設計視圖中的屬性中啓用 –
我注意到Timer被禁用,但是當我再次啓動調試時沒有任何操作。 @JohnGrabanski –