Converting to inches

1011 views
Skip to first unread message

Robert Jacobson

unread,
Sep 15, 2003, 3:33:56 PM9/15/03
to
The size of a form is measured in pixels. The normal measurement is 96
pixels per inch (although this apparently isn't always true, see the link
below.)

However, if you're trying to determine the actual size of a form on the
monitor, that will be difficult -- it's unlikely that the user's monitor
will be displaying exactly 96 pixels per inch. Consider that you can change
the screen resolution, for example, from 800 x 600 to 1024 x 768. The form
might be the "right" size in inches at one resolution, but won't be at
another resolution. To calculate the actual size, you'd need to know the
viewable size of the monitor, along with the environment's screen
resolution.

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/overview/highdpi.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/aboutGDIPlus/coordinatesystemsandtransformations/typesofcoordinatesystems.asp


"Brent Hoskisson" <brentho...@colliergov.net> wrote in message
news:029201c37bbb$43da32e0$a401...@phx.gbl...
> What is a unit of height and width of a form measured as
> (pixels?) and how can I convert that measurement to inches?
>
> Thanks
> Brent


Fergus Cooney

unread,
Sep 15, 2003, 4:07:59 PM9/15/03
to
Hi Brent,

A Form's width is in pixels, as you've found. Each Form (actually Control)
has a drawing surface controlled by a Graphics object. This has a property
DpiX which is Dots-Per-Inch-Horizontal, and a corresponding DpiY.

Try this:
Dim g As Graphics
g = SomeForm.CreateGraphics

MsgBox ("DpiX " & g.DpiX & vbCrLf _
"Width (mm) " & SomeForm.Width & vbCrLf _
"Width (inches) = " & SomeForm.Width / g.DpiX)

Regards,
Fergus


Herfried K. Wagner [MVP]

unread,
Sep 15, 2003, 6:11:00 PM9/15/03
to
Hello,

"Fergus Cooney" <filt...@tesco.net> schrieb:


> Try this:
> Dim g As Graphics
> g = SomeForm.CreateGraphics
>
> MsgBox ("DpiX " & g.DpiX & vbCrLf _
> "Width (mm) " & SomeForm.Width & vbCrLf _
> "Width (inches) = " & SomeForm.Width / g.DpiX)

\\\
g.Dispose()
///

SCNR

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet


Fergus Cooney

unread,
Sep 15, 2003, 6:23:18 PM9/15/03
to
Hi Herfried,

Thanks, I'm glad you didn't resist. It <is> better to use Dispose rather
than leaving it to the garbage collector. :-)

Regards,
Fergus


Herfried K. Wagner [MVP]

unread,
Sep 15, 2003, 6:35:38 PM9/15/03
to
Hello,

"Fergus Cooney" <filt...@tesco.net> schrieb:


> Thanks, I'm glad you didn't resist. It <is> better to use Dispose rather
> than leaving it to the garbage collector. :-)

For pens, brushes, graphics objects etc. the 'Dispose' method should always
(...) be called by the programmer, this will free unmanaged ressources.

Fergus Cooney

unread,
Sep 15, 2003, 7:41:43 PM9/15/03
to
Hi Herfried,

|| For pens, brushes, graphics objects etc. the 'Dispose'

|| method should always be called by the programmer.
|| This will free unmanaged ressources ...

.. earlier, and more timely, than the garbage collector - which will free
them when it eventually calls the object's Finalize routine.

Regards,
Fergus


Fergus Cooney

unread,
Sep 16, 2003, 6:36:04 AM9/16/03
to
Hi Herfried,

I've just discovered that C# has a special syntax for Dispose.

Graphics g = pic.CreateGraphics();
using (g)
{
g.DrawThisThatAndTheOther (x, y, p)
// Do other stuff with g.
: : :
} // g.Dispose is called automatically here.

Yet another shortcut that C# provides. I wonder why they left it out of
VB?

Regards,
Fergus

Cor

unread,
Sep 16, 2003, 7:05:48 AM9/16/03
to
Hi Fergus,
Maybe to compensate all the extra possibilities VB got from
Microsoft.visualbasic
:-)
Cor


Herfried K. Wagner [MVP]

unread,
Sep 16, 2003, 7:51:23 AM9/16/03
to
Hello,

"Cor" <n...@non.com> schrieb:


> Maybe to compensate all the extra possibilities VB got from
> Microsoft.visualbasic

LOL -- in C# they have operator overloading and unsafe code too... Maybe to
compensate all the extra possibilities VB got from 'Microsoft.VisualBasic'
too.

;-)

Herfried K. Wagner [MVP]

unread,
Sep 16, 2003, 7:50:30 AM9/16/03
to
Hello,

"Fergus Cooney" <filt...@tesco.net> schrieb:

I don't know, but I don't see big advantages in the 'using' syntax. It adds
one extra nesting level to the source code and hides the call to the
'Dispose' method.

Herfried K. Wagner [MVP]

unread,
Sep 16, 2003, 5:45:32 PM9/16/03
to
Hello,

"Fergus Cooney" <filt...@tesco.net> schrieb:

Somewhere in the documentation I read that 'Dispose' should be called by the
programmer for all GDI+ objects. I think that was a "recommendation".

;-)

Fergus Cooney

unread,
Sep 16, 2003, 7:09:48 PM9/16/03
to
Hi Herfried,

You're right, dispose() <is> a recommendation. Why have GDI resources tied
up waiting for the non-deterministic GC when you can free them as soon as.

Regards,
Fergus


Reply all
Reply to author
Forward
0 new messages