Apr 14th, 2005, 03:21 AM
#1
Thread Starter
Frenzied Member
Re: Converting Dialog Units into Pixels
No, doesn't seem to.
Have a go, put a label on the form and use my functions to try and place it as they have it on the form.
I use Microsoft Visual Basic 2005 . (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
Apr 14th, 2005, 03:46 AM
#2
Re: Converting Dialog Units into Pixels
Originally Posted by
Ideas Man
No, doesn't seem to.
Have a go, put a label on the form and use my functions to try and place it as they have it on the form.
Looks OK to me.
(I didn't know what the font for that label was supposed to be so i took a very rough guess)...
VB Code:
Public Class DialogUnits
Private Declare Function GetDialogBaseUnits Lib "user32" () As Integer
Private _Width As Integer
Private _Height As Integer
Public Sub New()
Call CalculateDialogUnits()
End Sub
Public ReadOnly Property Width() As Integer
Get
Return _Width
End Get
End Property
Public ReadOnly Property Height() As Integer
Get
Return _Height
End Get
End Property
Public Function GetHeightInPixels(ByVal dialogUnits As Integer) As Integer
Return (_Height * dialogUnits) \ 8
End Function
Public Function GetWidthInPixels(ByVal dialogUnits As Integer) As Integer
Return (_Width * dialogUnits) \ 4
End Function
Public ReadOnly Property Size() As SizeF
Get
Return New SizeF(_Width, _Height)
End Get
End Property
Private Sub CalculateDialogUnits()
Dim DialogUnits As Long = GetDialogBaseUnits
_Width = LongManipulation.GetLoWord(DialogUnits)
_Height = LongManipulation.GetHiWord(DialogUnits)
End Sub
End Class
Public Class LongManipulation
Public Shared Function GetLoWord(ByVal sourceLong As Long) As Integer
Return CType(sourceLong And &HFFFF&, Integer)
End Function
Public Shared Function GetHiWord(ByVal sourceLong As Long) As Integer
Return CType((sourceLong >> 16) And &HFFFF&, Integer)
End Function
Public Shared Function IntegersToLong(ByVal hiWord As Integer, ByVal loWord As Integer) As Long
Return (hiWord << 16) Or loWord
End Function
End Class
Attached Images
I don't live here any more.
Apr 14th, 2005, 03:47 AM
#3
Re: Converting Dialog Units into Pixels
Here's the code for the button...
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim du As DialogUnits = New DialogUnits
With Label1
.Location = New Point(du.GetWidthInPixels(115), du.GetHeightInPixels(8))
.Size = New Size(du.GetWidthInPixels(195), du.GetHeightInPixels(24))
End With
Me.Size = New Size(du.GetWidthInPixels(317), du.GetHeightInPixels(193))
End Sub
I don't live here any more.
Apr 14th, 2005, 04:00 AM
#4
Thread Starter
Frenzied Member
Re: Converting Dialog Units into Pixels
Nah, see that's too big. Compare the form when you click the button to the picture or any wizard in Windows such as the New Connection Wizard in Windows XP. The inner area is bigger than the entire form for the wizard.
Which makes me think that the numbers are supposed to be some decimal number, not whole integers because when you divide by 4 and 8 for width and height respectivly, you get like 1 & 2 (or 2 & 1, one or the other) which is too big, and when you set it to the size of the dialog units, it's too small.
BTW, the title font is Verdana size 12, Bold.
I use Microsoft Visual Basic 2005 . (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width