Link to home
Start Free TrialLog in
Avatar of buchholt
buchholtFlag for Denmark

asked on

Drawing lines in millimeters in vb.net

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 ...
Avatar of ctm5
ctm5

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

ASKER

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!!!
What are you using to measure? Are you measuring on the monitor or on a printout? Try a screen capture, then print and measure.
I am measuring on the monitor with a ruler
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.

ctm5
ASKER CERTIFIED SOLUTION
Avatar of jrscherer
jrscherer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Jack.net