455,032 Members | 1,161 Online
Need help? Post your question and get tips & solutions from a community of 455,032 IT Pros & Developers. It's quick & easy.

# Converting to inches

 P: n/a 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 Replies

 P: n/a 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" 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

 P: n/a 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

 P: n/a Hello, "Fergus Cooney" 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

 P: n/a Hi Herfried, Thanks, I'm glad you didn't resist. It better to use Dispose rather than leaving it to the garbage collector. :-) Regards, Fergus Nov 20 '05 #5

 P: n/a Hello, "Fergus Cooney" schrieb: Thanks, I'm glad you didn't resist. It 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

 P: n/a 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

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

 P: n/a Hello, "Fergus Cooney" 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

 P: n/a Hello, "Cor" 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

 P: n/a Hello, "Fergus Cooney" 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

 P: n/a Hi Herfried, You're right, dispose() 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 discussion thread is closed

Replies have been disabled for this discussion.