Mineten

Mineten

  • NA
  • 5
  • 16.3k

C#(Windows forms application) Adding triangle, polygon +more

Oct 9 2014 10:23 AM
Hello. I have been learning to do the graphic library and there are some things that I have no idea how to do and didn't find any information that could help me.

I wanted to add 4 shapes: Triangle, Square, Polygon and Circle.
 
This code is working when I added Ellipses and Rectangle but it's not working for other 4. I think it's because I should use different code rather System.Drawing.Graphics but I don't know which. For the triangle I have read that I can use 3 lines but I'm not sure how I should put the code so it's working correctly.

private void buttonSquare_Click(object sender, EventArgs e)
{
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red, 10);

System.Drawing.Graphics formGraphics = this.CreateGraphics();

Random random = new Random();
int randomXPos1 = random.Next(0, 200);
int randomYPos1 = random.Next(0, 200);
int randomWidth = random.Next(0, 100);
int randomHeight = random.Next(0, 100);


formGraphics.DrawSquare(myPen, randomXPos1, randomYPos1, randomWidth, randomHeight);
 
 }
Another thing that I wanted to add are 3 buttons. Undo, Redo and Clear all but I also have no idea what are the codes for these. 
If anyone could help me, I would really appreciate it :) 

Answers (1)