Click here to Skip to main content
16,004,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

May any help me with this...

I want to write a program to let me draw a line or any shape, with the mouse, for example. Then gives me how long is it with inches or whatsoever. Not this, but I need it to measure any shape's length as though it is a line. To illustrate,I need to measure the length of the circle from one specific point to another one.

Thanks a lot,
Posted

I assume from what you say that this is basically "how do I get the length of a line between two points that I click with the mouse?" - since you imply that you can already draw the shapes.
If so, then it is really, really easy: just use Pythagoras!
C#
Point startPoint = new Point(0, 0);
bool down = false;
private void panel1_MouseDown(object sender, MouseEventArgs e)
    {
    startPoint = e.Location;
    down = true;
    }

private void panel1_MouseMove(object sender, MouseEventArgs e)
    {
    if (down)
        {
        Point endPoint = e.Location;
        double length = Math.Sqrt(Math.Pow(endPoint.X - startPoint.X, 2) + Math.Pow(endPoint.Y - startPoint.Y, 2));
        label1.Text = length.ToString();
        }
    }

private void panel1_MouseUp(object sender, MouseEventArgs e)
    {
    down = false;
    }
 
Share this answer
 
As the screen is measured in pixels, although you can retrieve the screen resolution in dpi, it is not really precise. As it is really hard to make a program see, as a human sees, to be able to measure arcs and so on, you have to define primitives, and let the user draw/fit those primitives over the scanned image. Than, by having the geometrical properties of primitive drawn, you can also give several measurements/calculations. For that, you actually need to write a program like CorelDraw or InkScape (a little bit simpler). Although you have 2d vector graphics support in .net, creating such a program is not an easy task. You could start here: Simple Vector Shapes[^]
 
Share this answer
 
Comments
Zoltán Zörgő 2-Jun-12 4:39am    
I am really interested why is the downvote...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900