-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom Circles.cs
More file actions
66 lines (59 loc) · 2.05 KB
/
Random Circles.cs
File metadata and controls
66 lines (59 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 Graphics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Close window when exit button pressed
private void cmdQuit_Click(object sender, EventArgs e)
{
Close();
}
// Clar graphics window
private void cmdClear_Click(object sender, EventArgs e)
{
Refresh();
}
// Create black circle of 50 diameter at point (50,50)
private void cmdEllipse_Click(object sender, EventArgs e)
{
System.Drawing.Graphics graphics;
graphics = pnlDraw.CreateGraphics();
Pen penColour = new Pen(Color.BlueViolet);
graphics.DrawEllipse(penColour, 50, 50, 50, 50);
}
// Draw random circles on graphics window
private void cmdRandomCircles_Click(object sender, EventArgs e)
{
int x, y, radius;
Random rand = new Random();
x = rand.Next(pnlDraw.Width);
y = rand.Next(pnlDraw.Height);
radius = 50;
System.Drawing.Graphics graphics;
graphics = pnlDraw.CreateGraphics();
Color Colour = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
Pen penColour = new Pen(Colour);
graphics.DrawEllipse(penColour, x, y, radius, radius);
}
// Draw black line from the top left corner to the bottom right
private void cmdLines_Click(object sender, EventArgs e)
{
System.Drawing.Graphics graphics;
graphics = pnlDraw.CreateGraphics();
Pen penColour = new Pen(Color.Black);
graphics.DrawLine(penColour, 0, 0, pnlDraw.Width, pnlDraw.Height);
}
}
}