[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Drawing lines in millimeters in vb.net

Posted on 2006-05-18
7
Medium Priority
?
1,891 Views
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 ...
0
Comment
Question by:buchholt
  • 3
  • 2
  • 2
7 Comments
 
LVL 6

Expert Comment

by:ctm5
ID: 16713853
How are you drawing the line? If you are using a graphics object, you can set the PageUnit to be GraphicsUnit.Millimeter.
0
 

Author Comment

by:buchholt
ID: 16713904
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!!!
0
 
LVL 6

Expert Comment

by:ctm5
ID: 16713963
What are you using to measure? Are you measuring on the monitor or on a printout? Try a screen capture, then print and measure.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:buchholt
ID: 16714010
I am measuring on the monitor with a ruler
0
 
LVL 6

Expert Comment

by:ctm5
ID: 16714251
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
0
 
LVL 9

Accepted Solution

by:
jrscherer earned 1500 total points
ID: 16715374
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.  

Jack.net
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 16715407
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
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

831 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