Drawing lines in millimeters in

Posted on 2006-05-18
Last Modified: 2008-02-01
Hi there,

How do I draw a line of X millimeters in a picturebox.
When putting a ruler onto the screen(monitor physically), the drawn line and ruler should be equal in size.

I need it for VB.Net

- Thanks ...
Question by:buchholt
    LVL 6

    Expert Comment

    How are you drawing the line? If you are using a graphics object, you can set the PageUnit to be GraphicsUnit.Millimeter.

    Author Comment

    I'm drawing like this:

            Dim g As Graphics = e.Graphics
            Dim p As New Pen(Color.Black, 1)
            g.PageUnit = GraphicsUnit.Millimeter

            Dim a As New PointF(0, 50)
            Dim b As New PointF(100, 50)

            g.DrawLine(p, a, b)

    ... this does not give my a line on 100 millimeters as I would expect - but a 116 millimeter long line!!!
    LVL 6

    Expert Comment

    What are you using to measure? Are you measuring on the monitor or on a printout? Try a screen capture, then print and measure.

    Author Comment

    I am measuring on the monitor with a ruler
    LVL 6

    Expert Comment

    I imagine there is a fair amount of distortion. Your monitor might not be adjusted exactly right. If you go into the monitor settings, you can probably fiddle with the settings so whatever guide it offers will match your ruler. Then try measuring your line in VB.

    Again, I suggest that you simply print out the line and measure it.

    LVL 9

    Accepted Solution

    Monitors can be old CRT or new LCD. With CRT i would say forget it. It will not be accurate nor stable. You may have a few % error.
    for LCD you have to know the pixel size. Usually it is around .265mm, resulting in 96 dots per inch.
    Take the width in mm of your screen and devide it by the total pixels in X (your Display Settings Property)
    On my 17" LCD I have 340 mm and 1280 pixels equals to a pixel size of .2656mm equals to 95.63DPI

    This is your base for drawing accurate size on screen. Now you can use any graphics unit

    Here an extract drom help:
    Member name Description
     Display Specifies the unit of measure of the display device. Typically pixels for video displays, and 1/100 inch for printers.  
     Document Specifies the document unit (1/300 inch) as the unit of measure.  
     Inch Specifies the inch as the unit of measure.  
     Millimeter Specifies the millimeter as the unit of measure.  
     Pixel Specifies a device pixel as the unit of measure.  
     Point Specifies a printer's point (1/72 inch) as the unit of measure.  
     World Specifies the world coordinate system unit as the unit of measure.
    LVL 9

    Expert Comment

    Oh, I forgot to say. The DPI setting of your computer is in ControlPanel/ Display/ Settings/ Advanced. Thsi setting is taken as the reference to convert between dimensional (mm or inches) and Pixels

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now