|
-
May 10th, 2010, 06:09 PM
#1
Basic c# question for my assignment
Hi,
I have to do an EtchaSketch program for my assignment. So far I have this code:
--------------------------------------…
public partial class Form1 : Form
{
int x = 50, y = 50; // starting position
Bitmap bm;
int x1 = 50, y1 = 50;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
bm = new Bitmap(this.Width, this.Height); // create a form-size bitmap
Graphics g = Graphics.FromImage(bm); // get a graphic object for the bitmap
g.FillEllipse(Brushes.Blue, x, y, 20, 20); // put a circle in the bitmap
this.BackgroundImage = bm; // use the bitmap as the form background
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics h = e.Graphics; // get a graphic object for the bitmap
h.FillEllipse(Brushes.Blue, x1, y1, 20, 20);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
string input;
input = keyData.ToString();
if (input == "Down")
{
y1 = y1 + 10;
Refresh();
return true;
}
return false; // return true if key processed, otherwise false
}
--------------------------------------…
At the moment when I press the down key, the second circle moves down the screen.
How do I make it so that when I press down, it forms a line (so basically makes a new circle and keeps the previous circle where it was), just like the etchasketch game.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|