Hey
What is the easiest way to make simple graphical figures in Win forms (basic geometrical figures like rectangles, triangles, circles etc.).
TNX
Hey
What is the easiest way to make simple graphical figures in Win forms (basic geometrical figures like rectangles, triangles, circles etc.).
TNX
Get a DC to some component (probably the form itself) and paint to it. Check out the Graphics class on msdn.
As mentioned use the Graphics class built into .net. It's basically a GDI+ wrapper and once you get into it, you can have a lot of fun. Here's a little starter to point you in the right direction.
Code:using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Paint += new PaintEventHandler(Form1_Paint); } void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.FillRectangle(Brushes.Green, new Rectangle(0, 0, 100, 100)); g.FillEllipse(Brushes.Red, new Rectangle(10, 10, 50, 50)); } } }
How can I use these graphics as "marks" on the form (e.g when I click on it, a label or a textbox shows the size of the rectangle in pixels).
Well, when you draw a rectangle you also save it's size. Then on a mouse event handler you see if that point is inside of the rectangle. If it's inside the rectangle, use that rectangles dimensions to set the Text property of some control.