Hi everyone,
I'm supposed to make a form with the basic shapes (circle, ellipse, pie, arc, etc...) drawn onto a panel. For each shape one will be hollow and one will be filled ontop of eachother. I can't seem to get the positions correct. All of the images are being drawn into eachother. I know it has to do with the x and y coordinates I have setup but I can't seem to figure out the correct numbers to put in to make them look nice. Is there a function or something that will align them all? Here's my code:
private void panel1_Paint(object sender, PaintEventArgs e)
{
#region Shapes
Graphics g = e.Graphics;
//initialize starting point variables
int x = 0;
int y = 0;
Pen blkPen = new Pen(Brushes.Black, 2); //width = 2
g.SmoothingMode = SmoothingMode.AntiAlias; //draws smooth lines
//draw circle and filled circle
recCircle = new Rectangle(new Point(x,y),new Size(40,40));
g.DrawEllipse(blkPen, recCircle);
g.FillEllipse(Brushes.Black, x, y + 60, 40, 40);
//draw ellipse and filled ellipse
int w = 60;
int h = 40;
recEllipse = new Rectangle(new Point(x,y),new Size(w,h));
g.DrawEllipse(blkPen, recEllipse);
recEllipse = new Rectangle(new Point(x,y+60), new Size(w,h));
g.FillEllipse(Brushes.Black, recEllipse);
//draw polygon
Point pt1 = new Point(x, y);
Point pt2 = new Point(x + 22, y + 12);
Point pt3 = new Point(x + 22, y + 32);
Point pt4 = new Point(x, y + 44);
Point pt5 = new Point(x - 22, y + 32);
Point pt6 = new Point(x - 22, y + 12);
Point[] myPoints = { pt1, pt2, pt3, pt4, pt5, pt6 };
g.DrawPolygon(blkPen, myPoints);
//points changed to not draw over original polygon
g.FillPolygon(Brushes.Black, myPoints);
//draw pie shape and fill pie shape
recPie = new Rectangle(new Point(x,y),new Size(80,80));
//create start and sweep
int startAngle = 0; //clockwise from x-axis
int sweepAngle = -60; //clockwise from startangle
g.DrawPie(blkPen, recPie, startAngle, sweepAngle);
g.FillPie(Brushes.Black, x, y + 60, 80, 80, startAngle, sweepAngle);
//draw and fill rectangle with beveled edges
blkPen.Width = 5;
recRectangle = new Rectangle(x, y, 50, 40);
g.DrawRectangle(blkPen, recRectangle);
blkPen.LineJoin = LineJoin.Bevel;
recRectangleBeveled = new Rectangle(x, y + 60, 50, 40);
g.DrawRectangle(blkPen, recRectangleBeveled);
//draw arc and filled pie
startAngle = 45;
sweepAngle = 180;
g.DrawArc(blkPen, x, y, 40, 40, startAngle, sweepAngle);
g.FillPie(Brushes.Black, x, y + 60, 40, 40, startAngle, sweepAngle);
#endregion
}
Here's what it looks like:
http://img3.imageshack.us/img3/8454/paintg.png