Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 16th, 2008, 07:06 PM
Registered User
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Code not working

hey everyone
i'm a beginner c# programmer and i've been learning out of a tutorial book
i've been making a pong game but for some reason, the animation for the ball isn't working

could you tell me if there's anything wrong with the code?
(copy, paste into c#)


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        int x = 46; //initial x position of ball
        int y = 46; //initial y position of ball
        int dx = 8; //position increment for ball on x axis
        int dy = 5; //position increment for ball on y axis
        Graphics g;
        public Form1()
            this.Paint +=new PaintEventHandler(Form1_Paint);

        private void Form1_Paint(object sender, PaintEventArgs e)
            g = e.Graphics;
            SolidBrush brush = new SolidBrush(Color.Black);
            g.FillEllipse(brush, x, y, 10, 10);

        private void timer1_Tick(object sender, EventArgs e)

        private void moveBall()
            if ((x + dx < 0) || (x + dx > 300)) dx = -dx;
            if ((y + dy < 0) || (y + dy > 255)) dy = -dy;
            x = x + dx;
            y = y + dy;

Old February 17th, 2008, 03:20 PM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

By default the 'Tick' event doesn't fire, you have to call timer1.Start();

/- Sam Judson : Wrox Technical Editor -/

Similar Threads
Thread Thread Starter Forum Replies Last Post
Working Code - Ch15 slurp56 BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 3 April 24th, 2013 10:32 AM
Code not working well vinish Beginning PHP 2 November 11th, 2005 08:02 PM
Select From Where Code not working...help bidatad Access VBA 2 April 1st, 2005 03:25 PM
Working with code behind - How To pinkuisadear ASP.NET 1.0 and 1.1 Basics 7 March 11th, 2005 01:13 AM
code not working Toka1 Javascript How-To 12 December 17th, 2003 05:08 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.