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 :)
Loading
Luke LeonPosted Oct 29, 2014, 3:12 AM
https://social.msdn.microsoft.com/Forums/en-US/10ecc171-d008-4a77-91d0-c47b770210f5/draw-triangle-with-gdi?forum=Vsexpressvcs
http://msdn.microsoft.com/en-us/library/sfwzeec0%28v=vs.90%29.aspx
About the undo, redo and clear features, this depends on how you want to develop your application. For example, if you are loading an image and draw different shapes, you can keep a copy of the image after each step you do, so that you can return to the previous state when you select undo. You can use the same approach on any action (redo, clear, etc.) you want to do on the image.
Note that if you want to create an interactive drawing application that gives the user the ability to draw different shapes using mouse-drag on the image, you might need to use a programming toolkit (like leadtools) that supports annotations features. You can find more information here.