473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Converting to inches

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
Nov 20 '05 #1
11 17252
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/de...ew/highdpi.asp

http://msdn.microsoft.com/library/de...atesystems.asp


"Brent Hoskisson" <br************@colliergov.net> wrote in message
news:02****************************@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

Nov 20 '05 #2
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
Nov 20 '05 #3
Hello,

"Fergus Cooney" <fi******@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
Nov 20 '05 #4
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
Nov 20 '05 #5
Hello,

"Fergus Cooney" <fi******@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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
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

Nov 20 '05 #7
Cor
Hi Fergus,
Maybe to compensate all the extra possibilities VB got from
Microsoft.visualbasic
:-)
Cor
Nov 20 '05 #8
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
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?


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 · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #9
Hello,

"Cor" <no*@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 · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #10
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
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.


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

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #11
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
Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SpookyTooth | last post by:
I am trying to write a program that will convert a height of a person from feet and inches to centimeters. I want to use the relationship: 1 foot = 30.48 cm and 1 inch = 2.54 cm. I am trying to get...
3
by: SpookyTooth | last post by:
I am trying to write a program that will convert a height of a person from feet and inches to centimeters. I want to use the relationship: 1 foot = 30.48 cm and 1 inch = 2.54 cm. I am trying to get...
1
by: printline | last post by:
Hello I need a javascript that converts mm to inches. Ex. I have a drop down menu in my form where users can choose either mm or inches. If they choose inches for example i have two text...
4
by: keith | last post by:
I am writing a simple program to convert mm to feet and inches. I have it as follows: #include <stdio.h> #include <math.h> void main() { int x=11; float mm=0; float answer=0;
4
by: onefry | last post by:
Hey I have this prog that i'm working on, starting my first c++ class and kind of a n00b to programming here it is #include <iostream> #include <cstdlib> using namespace std;
6
by: bratiskovci | last post by:
1. How do I change the program so that the program does not terminate after completing one conversion. Instead, the program should continue to convert values until the user indicates that he/she...
3
by: socondc22 | last post by:
Im stuck at this point. The way i was trying to do this was running if statement around my void function and then a else if statement around a different void function but it didnt work... right now...
3
by: pratik.best | last post by:
Hi, I am creating a software for a school. They are using dot matrix printer and have preprinted stationary. Now the paper size is 6 inches, and they are using tractor feed. How can I stop the...
2
by: Rob | last post by:
Hi Gurus, Is there any way to convert Centimeter or Inches to Pixel. Thanks for any help you can provide. Rob.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.