Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > VB.NET > Windows Forms

Windows Forms Discussion related to Winforms application development

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-19-2010, 11:47 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2009
Posts: 21
Reputation: 12
dineshkumaar is on a distinguished programming path ahead
Question Changing Measurement Units of Form to from Pixels to Twips

Hi everybody!

Is there any way so that i can set the measurement unit of a form from Pixels to Twips?

Regards

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-20-2010, 3:04 AM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,127
Reputation: 542
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

No, it's not. You'll have to perform the conversion yourself. Here's how it's done when upgrading VB6 code to VB.NET:
Code:
Private Shared Sub SetUpTwipsPerPixel(ByVal Optional Force As Boolean = False)
    If (Not Support.m_IsTwipsPerPixelSetUp OrElse Force) Then
        Support.m_TwipsPerPixelX = 0
        Support.m_TwipsPerPixelY = 0
        Try 
            Dim dC As IntPtr = NativeMethods.GetDC(NativeMethods.NullIntPtr)
            If Not dC.Equals(NativeMethods.NullIntPtr) Then
                Support.m_TwipsPerPixelX = (1440 / CDbl(NativeMethods.GetDeviceCaps(dC, &H58)))
                Support.m_TwipsPerPixelY = (1440 / CDbl(NativeMethods.GetDeviceCaps(dC, 90)))
                NativeMethods.ReleaseDC(NativeMethods.NullIntPtr, dC)
            End If
        Catch exception1 As Exception
            ProjectData.SetProjectError(exception1)
            ProjectData.ClearProjectError
        End Try
        Support.m_IsTwipsPerPixelSetUp = True
        If ((Support.m_TwipsPerPixelX = 0) OrElse (Support.m_TwipsPerPixelY = 0)) Then
            Support.m_TwipsPerPixelX = 15
            Support.m_TwipsPerPixelY = 15
            VB6Errors.RaiseError(7, Resources.GetResourceString("Misc_SetUpTwipsPerPixel"))
        End If
    End If
End Sub
As you can see, it involves invoking the Windows API. As such, it's a bit of a pain but you can implement something similar yourself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-20-2010, 8:02 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,328
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

You can reference Microsoft.VisualBasic.Compatibility and use these properties and functions:
Code:
Microsoft.VisualBasic.Compatibility.VB6.TwipsPerPixelX 
TwipsPerPixelX
TwipsToPixelsX(x)
TwipsToPixelsY(y)
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-04-2010, 2:01 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jun 2009
Posts: 21
Reputation: 12
dineshkumaar is on a distinguished programming path ahead
Default

Thankyou very much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-04-2010, 7:40 PM
jmcilhinney's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Aug 2004
Location: Sydney, Australia
Age: 40
Posts: 6,127
Reputation: 542
jmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalistjmcilhinney VB.NET gold medalist
Default

Quote:
Originally Posted by JohnH View Post
You can reference Microsoft.VisualBasic.Compatibility and use these properties and functions:
Code:
Microsoft.VisualBasic.Compatibility.VB6.TwipsPerPixelX 
TwipsPerPixelX
TwipsToPixelsX(x)
TwipsToPixelsY(y)
I'm not 100% sure why but those methods have been marked obsolete in .NET 4.0, so it's probably best not to rely on them. I'm not sure what that means for upgraded VB6 code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-04-2010, 9:24 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,328
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Quote:
Note: This API is now obsolete.
Indicates to me the whole VB6 thing is obsolete: Microsoft.VisualBasic.Compatibility.VB6 Namespace () Time to move on by getting started with VB.Net
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Tags
form measurement units, measurement etc., pixels to twips


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 3:12 PM.

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.