Button click action to move a ball : Animation « 2D Graphics « C# / C Sharp






Button click action to move a ball

Button click action to move a ball

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

public class ButtonToMove : Form {
  private int x = 50, y = 50;
  private Button move = new Button();

  public ButtonToMove() {
    move.Text = "Move";
    move.Location = new Point(5,5);
    Controls.Add(move);
    move.Click += new EventHandler(Move_Click);
  }    
  protected void Move_Click(object sender, EventArgs e) {
    x += 9;
    y += 9;
    Invalidate();
  }
  protected override void OnPaint( PaintEventArgs e )   {
    Graphics g = e.Graphics;
    Brush red = new SolidBrush(Color.Red);
    g.FillEllipse(red ,x ,y, 20 ,20);
    base.OnPaint(e);
  }
  public static void Main( ) {
    Application.Run(new ButtonToMove());
  }         
}
           
       








Related examples in the same category

1.Object collisionObject collision
2.Animates a circleAnimates a circle
3.Uses a thread to Animate a ballUses a thread to Animate a ball
4.Animates an imageAnimates an image
5.Animation and double bufferAnimation and double buffer
6.Timer based animationTimer based animation
7.No Flicker (Flicker Free) AnimationNo Flicker (Flicker Free) Animation
8.Animate ImageAnimate Image
9.Animate DemoAnimate Demo
10.Animate Image with ImageAnimator