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
"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
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
"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
Thanks, I'm glad you didn't resist. It <is> better to use Dispose rather
than leaving it to the garbage collector. :-)
Regards,
Fergus
"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.
|| 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
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" <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.
;-)
"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.
"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".
;-)
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