I can draw a circle, but I cannot draw a rectangle or draw a line. Can you guys see what it is that I'm missing?
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Shapes
{
public abstract class Shapes
{
protected int x1, y1, x2, y2;
public void setCoordinates(int x1, int y1, int x2, int y2)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public abstract void drawShape(Graphics g);
public abstract void drawShapes(Graphics g);
}
public class Circle : Shapes
{
public Circle()
{
setCoordinates(0, 0, 0, 0);
}
public Circle(int a, int b, int w, int h)
{
setCoordinates(a, b, w, h);
}
public override void drawShape(Graphics g)
{
g.DrawEllipse(new Pen(Color.Green), x1, y1, x2, y2);
}
public override void drawShaper(Graphics q)
{
q.DrawRectangle(new Pen(Color.Green), x1, y1, x2, y2);
}
}
public class Rectangle : Shapes
{
public Rectangle()
{
setCoordinates(0, 0, 0, 0);
}
public Rectangle(int a, int b, int w, int h)
{
setCoordinates(a, b, w, h);
}
public override void drawShape(Graphics g)
{
g.DrawEllipse(new Pen(Color.Green), x1, y1, x2, y2);
}
public override void drawShaper(Graphics q)
{
q.DrawRectangle(new Pen(Color.Green), x1, y1, x2, y2);
}
}
public class TestShapes : Form
{
private static Circle c;
private static int shape;
private static Rectangle r;
public static void Main()
{
shape = 1;
c = new Circle(100, 100, 50, 50);
r = new Rectangle(100, 100, 50, 50);
Application.Run(new TestShapes());
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("Testing C# inheritance!", new Font("Arial", 18),
new SolidBrush(Color.Blue), 5, 5);
switch (shape)
{
case 1:
c.drawShape(g);
break;
case 2:
r.drawShape(g);
break;
case 3:
break;
}
}
}
}