Practice - Chapter 3- Timer
Practice - Chapter 3- Timer
Exercise 1:
Develop an application having a circle on it screen. Users could use the “Left”, “Right”, “Up”,
and “Down” key to move the graphic object.
plMain (Panel)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ControlingObject
{
public partial class Form1 : Form
{
Graphics gp;
SolidBrush myBrush;
Color myColor;
Point pos;
public Form1()
{
InitializeComponent();
gp = this.plMain.CreateGraphics();
myColor = Color.Blue;
pos.X = 100;
pos.Y = 100;
Exercise 2: Develop an application having a circle on it screen. The circle moves from the left to
the right of the screen automatically.
.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MovingObject
{
public partial class Form1 : Form
{
Graphics gp;
SolidBrush myBrush;
Color myColor;
Point pos;
public Form1()
{
InitializeComponent();
gp = this.plMain.CreateGraphics();
myColor = Color.Blue;
pos.X = 100;
pos.Y = 100;
}
this.plMain.Refresh();
}
}
}