How to draw lines of fix measurements?

Hi all,

Can any one tell me how to draw the lines of fix measurements (like

5cm, 4 inch etc.) in .Net. I am doing a project for my academic

course in which I have to draw/plot lines with various measurements

dynamically provided by the user.

Any help is welcome.....

So guys please reply me at:
abhi.win@gmail.com

if anyone knows solution for this....

Thanks,
Abhi Win



Answer this question

How to draw lines of fix measurements?

  • BaradaNikto

    While I understand what you are saying, resolution independent graphics are about the length as well as the thickness. It is about having the same graphics on each screen, independent of its resolution (apart from the fact that higher resolution produces better image quality of course).

    The .Net framework has this philosophy as well: the drawing methods can be measured in pixels as well as inches or millimeters (and some more).

    This is also the reason why there is no DrawPixel method. The resolution independent version of DrawPixel is a dot with a certain radius. Therefore you will have to use FillEllipse with a radius of 1 and units set to pixels in order to do something as simple as plotting a pixel. I think this is a good philosophy and forces to people to think in this way.

    my two cents.



  • Sander de Koning

    Well, if they are horizontal or vertical then it's simple:

    g.DrawLine(pen, 0, 0, 50, 0);

    or

    g.DrawLine(pen, 0, 0, 0, 50);

    If they are not horizontal or vertical then I assume you know an angle for the direction and in this case you need to do something like:

    g.DrawLine(pen, 0, 0, Math.Cos(angle) * 50, Math.Sin(angle) * 50);

     


  • Panky

    Thanks for that Mike, but I want to draw lines like 5cm in LENGTH, not thick.

    Reply.


  • Pam_4i2i

    you can set the PageUnit property of the Graphics object to something like millimeter or inch like in the following example that draws a 5 cm thick line:

     

      protected override void OnPaint(PaintEventArgs e)
      {
       base.OnPaint(e);

       e.Graphics.PageUnit = GraphicsUnit.Millimeter;

       using (Pen pen = new Pen(Color.Black, 50.0f))
        e.Graphics.DrawLine(pen, 0, 0, 100, 100);
      }


  • How to draw lines of fix measurements?