WINDOWS PROGRAMMING
Graphic device interface
Dr. Le Van Vinh
FIT - HCMUTE
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 [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace ControlingObject
{
public partial class Form1 : Form
{
Graphics gp;
SolidBrush myBrush;
Color myColor;
Point pos;
public Form1()
{
InitializeComponent();
gp = [Link]();
myColor = [Link];
myBrush = new SolidBrush(myColor);
pos.X = 100;
pos.Y = 100;
private void Form1_Load(object sender, EventArgs e)
{
private void plMain_Paint(object sender, PaintEventArgs e)
{
[Link](myBrush, pos.X, pos.Y, 50, 50);
[Link]();
}
private void plMain_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch ([Link])
{
case [Link]:
[Link].X = [Link].X - 5;
break;
case [Link]:
[Link].X = [Link].X + 5;
break;
case [Link]:
[Link].Y = [Link].Y - 5;
break;
case [Link]:
[Link].Y = [Link].Y + 5;
break;
default:
break;
}
[Link]();
}
}
}
Requirements: Develop other functions:
+ Adjust size of the circle by pressing keys (L: larger, N: smaller).
+ Adjust color of the circel by pressing “C” key.
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 [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace MovingObject
{
public partial class Form1 : Form
{
Graphics gp;
SolidBrush myBrush;
Color myColor;
Point pos;
public Form1()
{
InitializeComponent();
gp = [Link]();
myColor = [Link];
myBrush = new SolidBrush(myColor);
pos.X = 100;
pos.Y = 100;
}
private void Form1_Load(object sender, EventArgs e)
{
[Link] = 500;
[Link]();
private void plMain_Paint(object sender, PaintEventArgs e)
{
[Link](myBrush, pos.X, pos.Y, 50, 50);
}
private void myTime_Tick(object sender, EventArgs e)
{
[Link].X = [Link].X + 10;
[Link]();
}
}
}
Requirements: Develop other functions allowing:
+ When the circle reaches the right edge of the screen, it automatically run backwards.
+ Users could use the key to move the circle up or down (while the circle still moves forwards or
backwards)